Class: Compositor::Composite

Inherits:
Base
  • Object
show all
Defined in:
lib/compositor/composite.rb

Direct Known Subclasses

ListCompositor, MapCompositor

Instance Attribute Summary collapse

Attributes inherited from Base

#attrs, #context, #root

Instance Method Summary collapse

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

#collectionObject

Returns the value of attribute collection.



3
4
5
# File 'lib/compositor/composite.rb', line 3

def collection
  @collection
end

#rendererObject

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

Returns:

  • (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_hashObject



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