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 protected
- #model ⇒ Composition readonly protected
Instance Method Summary collapse
- #attributes ⇒ Hash private
-
#existing_attributes(name) ⇒ Hash
private
Retrieve the attributes of the interface by name.
-
#initialize(model, client = nil) ⇒ Vedeu::DSL::Composition
constructor
Returns an instance of DSL::Composition.
- #new_attributes(name) ⇒ Hash private
- #template_attributes(name, lines) ⇒ Hash private
-
#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Interfaces<Vedeu::Interface>
Load content from an ERb template.
-
#view(name = '', &block) ⇒ Vedeu::Interfaces<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.
15 16 17 18 |
# File 'lib/vedeu/dsl/composition.rb', line 15 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, protected)
78 79 80 |
# File 'lib/vedeu/dsl/composition.rb', line 78 def client @client end |
#model ⇒ Composition (readonly, protected)
82 83 84 |
# File 'lib/vedeu/dsl/composition.rb', line 82 def model @model end |
Instance Method Details
#attributes ⇒ Hash (private)
108 109 110 111 112 113 |
# File 'lib/vedeu/dsl/composition.rb', line 108 def attributes { client: client, parent: model, } end |
#existing_attributes(name) ⇒ Hash (private)
Retrieve the attributes of the interface by name.
103 104 105 |
# File 'lib/vedeu/dsl/composition.rb', line 103 def existing_attributes(name) Vedeu.interfaces.by_name(name).attributes end |
#new_attributes(name) ⇒ Hash (private)
95 96 97 |
# File 'lib/vedeu/dsl/composition.rb', line 95 def new_attributes(name) attributes.merge!(existing_attributes(name)) end |
#template_attributes(name, lines) ⇒ Hash (private)
89 90 91 |
# File 'lib/vedeu/dsl/composition.rb', line 89 def template_attributes(name, lines) new_attributes(name).merge!(lines: lines) end |
#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Interfaces<Vedeu::Interface>
TODO:
More documentation required.
Load content from an ERb template.
65 66 67 68 69 70 71 72 |
# File 'lib/vedeu/dsl/composition.rb', line 65 def template_for(name, filename, object = nil, = {}) content = Vedeu::Template.parse(object, filename) lines = Vedeu::Wordwrap.for(content, ) new_model = model.member.build(template_attributes(name, lines)) model.add(new_model) end |
#view(name = '', &block) ⇒ Vedeu::Interfaces<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.
39 40 41 42 43 44 45 |
# File 'lib/vedeu/dsl/composition.rb', line 39 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 |