Class: Representable::Config::Definitions

Inherits:
Inheritable::Hash show all
Extended by:
Forwardable
Defined in:
lib/representable/config.rb

Overview

Stores Definitions from ::property. It preserves the adding order (1.9+). Same-named properties get overridden, just like in a Hash.

Overwrite definition_class if you need a custom Definition object (helpful when using representable in other gems).

Instance Method Summary collapse

Methods included from Inheritable::Hash::InstanceMethods

#clone, #inherit!

Constructor Details

#initialize(definition_class) ⇒ Definitions

TODO: cloneable!



25
26
27
28
# File 'lib/representable/config.rb', line 25

def initialize(definition_class)
  @definition_class = definition_class
  super()
end

Instance Method Details

#add(name, options, &block) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/representable/config.rb', line 30

def add(name, options, &block)
  if options[:inherit] and parent_property = get(name) # i like that: the :inherit shouldn't be handled outside.
    return parent_property.merge!(options, &block)
  end
  options.delete(:inherit) # TODO: can we handle the :inherit in one single place?

  self[name.to_s] = definition_class.new(name, options, &block)
end

#get(name) ⇒ Object



39
40
41
# File 'lib/representable/config.rb', line 39

def get(name)
  self[name.to_s]
end

#remove(name) ⇒ Object



43
44
45
# File 'lib/representable/config.rb', line 43

def remove(name)
  delete(name.to_s)
end