Class: Compositor::Composite
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
Attributes inherited from Base
Instance Method Summary collapse
- #composite? ⇒ Boolean
- #dsl(dsl, &block) ⇒ Object
-
#initialize(view_context, args = {}) ⇒ Composite
constructor
A new instance of Composite.
- #to_hash ⇒ Object
Methods inherited from Base
#include_root?, inherited, original_dsl_name, #to_h, #to_json, #with_root_element
Constructor Details
#initialize(view_context, args = {}) ⇒ Composite
Returns a new instance of Composite.
5 6 7 8 9 |
# File 'lib/compositor/composite.rb', line 5 def initialize(view_context, args = {}) super @collection_set = true if args.has_key?(:collection) self.collection ||= [] end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
3 4 5 |
# File 'lib/compositor/composite.rb', line 3 def collection @collection end |
#renderer ⇒ Object
Returns the value of attribute renderer.
3 4 5 |
# File 'lib/compositor/composite.rb', line 3 def renderer @renderer end |
Instance Method Details
#composite? ⇒ Boolean
17 18 19 |
# File 'lib/compositor/composite.rb', line 17 def composite? true end |
#dsl(dsl, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/compositor/composite.rb', line 21 def dsl(dsl, &block) original_generator = dsl.generator dsl.generator = self if self.collection && @collection_set && block # reset collection, we'll be mapping it via a block unmapped_collection = collection self.collection = [] unmapped_collection.each do |object| dsl.instance_exec(object, &block) end elsif block dsl.instance_eval &block end dsl.generator = original_generator if original_generator dsl.generator.collection << self if dsl.generator != self end |
#to_hash ⇒ Object
11 12 13 14 15 |
# File 'lib/compositor/composite.rb', line 11 def to_hash with_root_element do renderer.new(self, collection).render end end |