Class: RgGen::Core::Base::ComponentFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/core/base/component_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_name, layer) ⇒ ComponentFactory

Returns a new instance of ComponentFactory.



7
8
9
10
11
12
# File 'lib/rggen/core/base/component_factory.rb', line 7

def initialize(component_name, layer)
  @component_name = component_name
  @layer = layer
  @root_factory = false
  block_given? && yield(self)
end

Instance Attribute Details

#component_nameObject (readonly)

Returns the value of attribute component_name.



14
15
16
# File 'lib/rggen/core/base/component_factory.rb', line 14

def component_name
  @component_name
end

#layerObject (readonly)

Returns the value of attribute layer.



15
16
17
# File 'lib/rggen/core/base/component_factory.rb', line 15

def layer
  @layer
end

Instance Method Details

#create(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rggen/core/base/component_factory.rb', line 25

def create(*args)
  parent, sources =
    if root_factory?
      [nil, preprocess(args)]
    else
      [args.first, preprocess(args[1..])]
    end
  create_component(parent, sources) do |component|
    build_component(parent, component, sources)
    root_factory? && finalize(component)
  end
end

#root_factoryObject



21
22
23
# File 'lib/rggen/core/base/component_factory.rb', line 21

def root_factory
  @root_factory = true
end