Class: Retl::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/retl/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/retl/context.rb', line 5

def initialize(path, options={})
  path.dependencies.each do |name, dependency|
    if dependency.nil? && !options[name]
      raise ArgumentError, "This transformation depends on `name`"
    end

    self.class.send(:define_method, name) do 
      (dependency && dependency.call(options)) || options[name]
    end 
  end

  @_events = EventRouter.new
end

Instance Method Details

#_eventsObject



31
32
33
# File 'lib/retl/context.rb', line 31

def _events
  @_events
end

#execute_step(step, data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/retl/context.rb', line 19

def execute_step(step, data)
  if step.is_a?(Proc)
    instance_exec(data, self, &step)
  else
    if step.method(:call).arity.abs == 2
      step.call(data, self)
    else
      step.call(data)
    end
  end
end