Operabl
Railway oriented aproach for your classes. Operabl let you define steps in your class to be executed sequentially
Installation
Add this line to your application's Gemfile:
gem 'operabl'
And then execute:
$ bundle
Or install it yourself as:
$ gem install operabl
Usage
class ProcOp
include Operabl
step ->(ctx) {
ctx[:key] = ctx.params[:pkey]
ctx[:amethod_call] = amethod
}
def amethod
return "something else"
end
end
op = ProcOp.call({pkey: "something"})
op.failure? # => false
op.success? # => true
op[:key] # => "something"
op[:amethod_call] # => "something else"
class MethodOp
include Operabl
step :a
def a(ctx)
ctx[:key] = ctx.params[:pkey]
end
end
op = MethodOp.call({pkey: "something"})
op.success? # => true
op.result # => {}
class ComposedOp
include Operabl
step MethodOp
step :b
def b(ctx)
ctx.success!({status: 200, response: "OK"})
end
end
op = ComposedOp.call({pkey: "something else"})
op.success? # => true
op[:key] # => "something else"
op.result # => {status: 200, response: "OK"}
License
The gem is available as open source under the terms of the MIT License.