Class: Representable::Config::Definitions
- Inherits:
-
Inheritable::Hash
- Object
- Hash
- Inheritable::Hash
- Representable::Config::Definitions
- 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
- #add(name, options, &block) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(definition_class) ⇒ Definitions
constructor
TODO: cloneable!.
- #remove(name) ⇒ Object
Methods included from Inheritable::Hash::InstanceMethods
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, , &block) if [:inherit] and parent_property = get(name) # i like that: the :inherit shouldn't be handled outside. return parent_property.merge!(, &block) end .delete(:inherit) # TODO: can we handle the :inherit in one single place? self[name.to_s] = definition_class.new(name, , &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 |