Module: Operabl::ClassMethods

Defined in:
lib/operabl.rb

Instance Method Summary collapse

Instance Method Details

#call(context_params = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/operabl.rb', line 12

def call(context_params=nil)

  ctx = case context_params
  when Hash
    Operabl::Context.new(context_params)
  when Operabl::Context
    context_params
  else
    Operabl::Context.new({})
  end

  steps.each do |step_branch, step_def, options|
    if step_branch == ctx.branch
      case step_def
      when String, Symbol
        self.method(step_def).call(ctx)
      when Proc
        self.instance_exec ctx, &step_def
      else
        if step_def.respond_to? :call
          step_def.call(ctx)
        else
          raise "#{step_def.inspect} is invalid step argument"
        end
      end
      break if options[:fastforward]
    end

  end

  return ctx

end

#failure(step_def, options = {}) ⇒ Object



54
55
56
# File 'lib/operabl.rb', line 54

def failure(step_def, options={})
  steps << [:failure, step_def, options]
end

#step(step_def, options = {}) ⇒ Object



50
51
52
# File 'lib/operabl.rb', line 50

def step(step_def, options={})
  steps << [:success, step_def, options]
end

#stepsObject



46
47
48
# File 'lib/operabl.rb', line 46

def steps
  @steps ||= []
end