Class: Forkforge::Handler

Inherits:
Object show all
Defined in:
lib/forkforge/dsl/handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(handler_class, *args) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
9
10
11
# File 'lib/forkforge/dsl/handler.rb', line 5

def initialize handler_class, *args
  @handler = handler_class.split('::').inject(Object) do |mod, clazz|
    mod.const_get(clazz)
  end.new *args

  @delayed = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
18
19
20
# File 'lib/forkforge/dsl/handler.rb', line 13

def method_missing method, *args, &block
  if @handler.respond_to? method
    @handler.send(method, *args, &block)
    @delayed.clear
  else
    @delayed.unshift "#{method}"
  end
end

Instance Method Details

#parse(input) ⇒ Object



22
23
24
25
26
# File 'lib/forkforge/dsl/handler.rb', line 22

def parse input
  self.instance_eval %Q{
    #{File.read input}
  }
end