Class: Vedeu::DSL::Composition
- Inherits:
-
Object
- Object
- Vedeu::DSL::Composition
- Includes:
- Vedeu::DSL
- Defined in:
- lib/vedeu/dsl/composition.rb
Overview
DSL for creating collections of interfaces.
Instance Attribute Summary collapse
- #client ⇒ Object readonly private
- #model ⇒ Composition readonly private
Instance Method Summary collapse
- #attributes ⇒ Hash private
- #existing_interface_attributes(name) ⇒ Hash private
-
#initialize(model, client = nil) ⇒ Vedeu::DSL::Composition
constructor
Returns an instance of DSL::Composition.
- #new_attributes(name) ⇒ Hash private
-
#view(name = '', &block) ⇒ Vedeu::Model::Collection<Vedeu::Interface>
Define a view.
Methods included from Vedeu::DSL
Constructor Details
#initialize(model, client = nil) ⇒ Vedeu::DSL::Composition
Returns an instance of DSL::Composition.
18 19 20 21 |
# File 'lib/vedeu/dsl/composition.rb', line 18 def initialize(model, client = nil) @model = model @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, private)
53 54 55 |
# File 'lib/vedeu/dsl/composition.rb', line 53 def client @client end |
#model ⇒ Composition (readonly, private)
56 57 58 |
# File 'lib/vedeu/dsl/composition.rb', line 56 def model @model end |
Instance Method Details
#attributes ⇒ Hash (private)
78 79 80 81 82 83 |
# File 'lib/vedeu/dsl/composition.rb', line 78 def attributes { client: client, parent: model, } end |
#existing_interface_attributes(name) ⇒ Hash (private)
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vedeu/dsl/composition.rb', line 66 def existing_interface_attributes(name) if model.repository.registered?(name) stored = model.repository.find(name) stored.attributes else { name: name } end end |
#new_attributes(name) ⇒ Hash (private)
60 61 62 |
# File 'lib/vedeu/dsl/composition.rb', line 60 def new_attributes(name) attributes.merge!(existing_interface_attributes(name)) end |
#view(name = '', &block) ⇒ Vedeu::Model::Collection<Vedeu::Interface>
TODO:
More documentation required.
Define a view.
A view is just an Interface object.
When a view already exists, we take its attributes and use them as the basis for the newly defined view. This way we don’t need to specify everything again.
42 43 44 45 46 47 48 |
# File 'lib/vedeu/dsl/composition.rb', line 42 def view(name = '', &block) fail InvalidSyntax, 'block not given' unless block_given? new_model = model.member.build(new_attributes(name), &block) model.add(new_model) end |