New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

operabl

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

operabl

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Operabl

Railway oriented aproach for your classes. Operabl let you define steps in your class or module to be executed sequentially. Steps can be class methods, procs or other Operabl classes/modules.

Installation

Add this line to your application's Gemfile:

gem 'operabl'

And then execute:

$ bundle

Or install it yourself as:

$ gem install operabl

Usage

Include Operable in your Class/Module. Steps can be class methods, procs or other Operabl class/module

class ProcOp

    include Operabl

    step ->(ctx) {
        ctx[:key] = ctx.params[:pkey]
        ctx[:amethod_call] = amethod
    }

    def self.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"

Steps are Class level methods. This is because steps only work with a context provided, they don't change classes state.

class MethodOp

    include Operabl

    step :a

    def self.a(ctx)
        ctx[:key] = ctx.params[:pkey]
    end
end

op = MethodOp.call({pkey: "something"})
op.success? # => true
op.result # => {}

Another example of an Operabl as a step.

class ComposedOp

    include Operabl

    step MethodOp
    step :b

    def self.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"}

The result from #call is a Operabl::Context, it can be passed to a new Operabl call.

If Operation failed, AnotherOp is not going to succed but it will run any :failure step defined in it.


class AnotherOp

    include Operabl

    step :a
    failure :b

    def self.a(ctx)
        #do something
    end

    def self.b(ctx)
        #recover from failure
    end

end

op = Operation.call({pkey: "something else"})
op2 = AnotherOp.call(op)

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 06 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc