Module: GEPUB::BuilderMixin

Included in:
Builder, ResourceBuilder
Defined in:
lib/gepub/builder_mixin.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gepub/builder_mixin.rb', line 3

def method_missing(name, *args, &block)
  if Array === @last_defined_item &&
      @last_defined_item.size > 0 &&
      @last_defined_item[0].respond_to?(name.to_sym)

    if !(@last_defined_item[0].apply_one_to_multi ||
         @last_defined_item.size != 1) &&
        @last_defined_item.size != args.size
      warn "appling #{args} to #{@last_defined_item}: length differs."
    end

    @last_defined_item.each_with_index {
      |item, i|
      if item.apply_one_to_multi && args.size == 1
        item.send(name, args[0])
      elsif !args[i].nil?
        item.send(name, args[i])
      end
    }
  elsif @last_defined_item.respond_to?(name.to_sym)
    @last_defined_item.send(name, *args, &block)
  else
    super
  end
end