Class: RiCal::Component::ComponentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ri_cal/component.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ ComponentBuilder

Returns a new instance of ComponentBuilder


17
18
19
# File 'lib/ri_cal/component.rb', line 17

def initialize(component)
  @component = component
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(selector, *args, &init_block) ⇒ Object

:nodoc:


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ri_cal/component.rb', line 21

def method_missing(selector, *args, &init_block) #:nodoc:
  if(sub_comp_class = @component.subcomponent_class[selector])
    if init_block
      sub_comp = sub_comp_class.new(@component)
      if init_block.arity == 1
        yield ComponentBuilder.new(sub_comp)
      else
        ComponentBuilder.new(sub_comp).instance_eval(&init_block)
      end
      self.add_subcomponent(sub_comp)
    end
  else
    sel = selector.to_s
    sel = "#{sel}=" unless /(^(add_)|(remove_))|(=$)/ =~ sel
    if @component.respond_to?(sel)
      @component.send(sel, *args)
    else
      super
    end
  end
end