Parent

Files

POM::MetaStore

MetaStore serves as the base class for the Metadata class. It connects the file system to the POM model.

Attributes

parent[R]

Parent store, or root pathname. The topmost store should set this to the root pathname. All substores use this to reference their parent store (akin to parent directory).

pathname[R]

Filesystem path for the file store.

Public Class Methods

attr_accessor(name, options={}) click to toggle source

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
defaults() click to toggle source

Stores default values for attributes.

# File lib/pom/metastore.rb, line 296
def self.defaults
  @defaults ||= {}
end
listings() click to toggle source

What attributes are listings.

# File lib/pom/metastore.rb, line 301
def self.listings
  @listings ||= {}
end
new(parent, directory) click to toggle source

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

Public Instance Methods

[](name) click to toggle source

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
[]=(name, value) click to toggle source

Set value.

# File lib/pom/metastore.rb, line 63
def []=(name, value)
  @data[name.to_s] = value
end
entries() click to toggle source

List of available entries.

# File lib/pom/metastore.rb, line 91
def entries
  pathname.glob('*').map{ |path| File.basename(path) }
end
Also aliased as: keys
get!(name) click to toggle source

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
ignore() click to toggle source
# File lib/pom/metastore.rb, line 103
def ignore
  []
end
inspect() click to toggle source
# File lib/pom/metastore.rb, line 119
def inspect
  "#<#{self.class} #{@data.inspect}>"
end
key?(name) click to toggle source

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
keys() click to toggle source
Alias for: entries
load!(alt_path=nil) click to toggle source

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
merge!(other) click to toggle source

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
mesh!(other) click to toggle source

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
method_missing(sym, *args) click to toggle source
# 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
new_project_defaults() click to toggle source

Subclasses can override this.

# File lib/pom/metastore.rb, line 140
def new_project_defaults
  {}
end
read!() click to toggle source

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
root() click to toggle source

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
save!(path=nil) click to toggle source
# 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
to_h() click to toggle source

Return metadata in Hash form.

# File lib/pom/metastore.rb, line 240
def to_h
  read!
  @data.dup
end
to_yaml() click to toggle source

Convert to YAML.

# File lib/pom/metastore.rb, line 235
def to_yaml
  to_h.to_yaml
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.