module Operabl::ClassMethods

Public Instance Methods

call(context_params=nil) click to toggle source
# 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={}) click to toggle source
# File lib/operabl.rb, line 54
def failure(step_def, options={})
  steps << [:failure, step_def, options]
end
step(step_def, options={}) click to toggle source
# File lib/operabl.rb, line 50
def step(step_def, options={})
  steps << [:success, step_def, options]
end
steps() click to toggle source
# File lib/operabl.rb, line 46
def steps
  @steps ||= []
end