MetaStore serves as the base class for the Metadata class. It connects the file system to the POM model.
FileStore uses uniquely defined accessors.
# File lib/pom/metastore.rb, line 281 def self.attr_accessor(name, options={}) defaults[name.to_s] = options[:default] if options[:default] listings[name.to_s] = true if options[:default] == [] code = %{ def #{name} self["#{name}"] end def #{name}=(x) self["#{name}"] = x end } eval code end
Stores default values for attributes.
# File lib/pom/metastore.rb, line 296 def self.defaults @defaults ||= {} end
What attributes are listings.
# File lib/pom/metastore.rb, line 301 def self.listings @listings ||= {} end
New file store. The parent is either the parent Pathname or FileStore and directory is the name of the subdirectory with in it. If this is a toplevel FileStore then set parent to nil.
# File lib/pom/metastore.rb, line 23 def initialize(parent, directory) @parent = parent @data = {} @pathname = ( case parent when Pathname parent + directory when FileStore parent.pathname + directory else Pathname.new(directory) end ) end
Get value from store by name. The value will be cached so the file system is only hit once.
# File lib/pom/metastore.rb, line 53 def [](name) name = name.to_s if @data.key?(name) @data[name] else @data[name] = get!(name) end end
Set value.
# File lib/pom/metastore.rb, line 63 def []=(name, value) @data[name.to_s] = value end
List of available entries.
# File lib/pom/metastore.rb, line 91 def entries pathname.glob('*').map{ |path| File.basename(path) } end
Get a metadata entry, where entry is a pathname. If it is a directory, will create a new FileStore object.
# File lib/pom/metastore.rb, line 69 def get!(name) case name when String, Symbol path = @pathname + name #.to_s else path = name end if path.directory? data = FileStore.new(self, path.basename) elsif path.file? text = path.read.strip data = (/\A^---/ =~ text ? YAML.load(text) : text) data = data.to_list if self.class.listings[name] else data = self.class.defaults[name] data = instance_eval(&data) if Proc === data end data end
# File lib/pom/metastore.rb, line 119 def inspect "#<#{self.class} #{@data.inspect}>" end
Has a value been loaded from the file system?
# File lib/pom/metastore.rb, line 98 def key?(name) @data.key?(name.to_s) end
Load attribute values from file system.
# File lib/pom/metastore.rb, line 145 def load!(alt_path=nil) path = alt_path ? Pathname.new(alt_path) : pathname() path.glob('*').each do |file| #next if file.to_s.index(/[.]/) # TODO: rejection filter name = file.basename #path_to_name(file, path) self[name] = get!(file) end self end
Update underlying data table.
# File lib/pom/metastore.rb, line 248 def merge!(other) case other when Hash data = other when FileStore data = other.to_h end data.each do |name, value| @data[name.to_s] = value end end
Like merge! but does not update a value if it is empty.
# File lib/pom/metastore.rb, line 261 def mesh!(other) case other when Hash data = other when FileStore data = other.to_h end data.each do |name, value| case value when String, Array, Hash @data[name.to_s] = value unless value.empty? else @data[name.to_s] = value end end end
# File lib/pom/metastore.rb, line 39 def method_missing(sym, *args) name = sym.to_s case name when /=$/ super(sym, *args) unless args.size == 1 self[name] = args.first else super(sym, *args) unless args.empty? self[name] end end
Subclasses can override this.
# File lib/pom/metastore.rb, line 140 def new_project_defaults {} end
Load attribute values from file system, but only if the attribute is not currently set.
# File lib/pom/metastore.rb, line 157 def read! path = pathname path.glob('*').each do |file| #next if file.to_s.index(/[.]/) # TODO: rejection filter name = file.basename #path_to_name(file, path) self[name] = get!(file) unless key?(name) end self end
Return root pathname. The root pathname is the topmost point of entry of this metadata set, and is (almost certainly) the project root directory.
# File lib/pom/metastore.rb, line 110 def root case parent when Pathname then parent when FileStore then parent.root else nil end end
# File lib/pom/metastore.rb, line 168 def save!(path=nil) @pathname = Pathname.new(path) if path @data.each do |name, value| write!(name, value) end end
Generated with the Darkfish Rdoc Generator 2.