Class: Declarative::Definitions
- Inherits:
-
Hash
- Object
- Hash
- Declarative::Definitions
- Defined in:
- lib/declarative/definitions.rb
Defined Under Namespace
Modules: Inspect Classes: Definition
Instance Method Summary collapse
-
#add(name, options = {}, &block) ⇒ Object
#add is high-level behavior for Definitions#[]=.
-
#each(&block) ⇒ Object
TODO : test me!.
- #get(name) ⇒ Object
-
#initialize(definition_class) ⇒ Definitions
constructor
A new instance of Definitions.
Constructor Details
#initialize(definition_class) ⇒ Definitions
Returns a new instance of Definitions.
24 25 26 27 |
# File 'lib/declarative/definitions.rb', line 24 def initialize(definition_class) @definition_class = definition_class super() end |
Instance Method Details
#add(name, options = {}, &block) ⇒ Object
#add is high-level behavior for Definitions#[]=. reserved options:
:_features
:_defaults
:_base
:_nested_builder
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/declarative/definitions.rb', line 39 def add(name, ={}, &block) = [:_defaults].(name, ) if [:_defaults] # FIXME: pipeline? base = [:_base] if .delete(:inherit) and (parent_property = get(name)) base = parent_property[:nested] = parent_property.merge() # TODO: Definition#merge end if [:_nested_builder] [:nested] = build_nested( .merge( _base: base, _name: name, _block: block, ) ) end # clean up, we don't want that stored in the Definition instance. [:_defaults, :_base, :_nested_builder, :_features].each { |key| .delete(key) } self[name.to_s] = @definition_class.new(name, ) end |
#each(&block) ⇒ Object
TODO : test me!
29 30 31 |
# File 'lib/declarative/definitions.rb', line 29 def each(&block) # TODO : test me! values.each(&block) end |
#get(name) ⇒ Object
64 65 66 |
# File 'lib/declarative/definitions.rb', line 64 def get(name) self[name.to_s] end |