class Mother

Constants

VERSION

Attributes

data[R]

Public Class Methods

new(argument) click to toggle source
# File lib/mother.rb, line 9
def initialize(argument)
  self.class.argument_failure! unless argument.is_a?(Hash)

  @data = argument
end

Private Class Methods

argument_failure!() click to toggle source
# File lib/mother.rb, line 62
def argument_failure!
  raise ArgumentError.new('Must be a hash, or YAML/JSON filename')
end
create(thing) click to toggle source
# File lib/mother.rb, line 42
def create(thing)
  case thing
  when Array
    Collection.new self, thing
  when Hash
    new thing
  when String
    case
    when thing.match(/\.ya?ml$/)
      self.create YAML.load(File.read(thing))
    when thing.match(/\.json$/)
      self.create JSON.parse(File.read(thing))
    else
      thing
    end
  else
    thing
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/mother.rb, line 15
def [](key)
  self.class.create ___fetch(key)
end
keys() click to toggle source
# File lib/mother.rb, line 19
def keys
  @data.keys
end
method_missing(method, *args, &block) click to toggle source
# File lib/mother.rb, line 27
def method_missing(method, *args, &block)
  self[method]
end
respond_to_missing?(method, include_private = true) click to toggle source
Calls superclass method
# File lib/mother.rb, line 31
def respond_to_missing?(method, include_private = true)
  keys.include?(method) || keys.include?(method.to_s) || super
end
values() click to toggle source
# File lib/mother.rb, line 23
def values
  @data.values
end

Private Instance Methods

___fetch(key) click to toggle source
# File lib/mother.rb, line 37
def ___fetch(key)
  @data[key.to_sym] or @data[key.to_s]
end