0.01
No commit activity in last 3 years
No release in over 3 years
Pipes provides a Unix-like way to chain business objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.6.9, ~> 1.6
~> 10.3
 Project Readme

Pipes Build Status codebeat badge

Pipes provide a Unix-like way to chain business objects (interactors) in Ruby.

Installation

To start using Pipes, add the library to your Gemfile and run bundle install.

gem 'codequest_pipes'

High-level usage example

FLOW = Projects::Match         | # NOTE: each of the elements must inherit from
       Projects::Validate      | # Pipes::Pipe!
       Projects::UpdatePayment |
       Projects::SaveWithReport
context = Pipes::Context.new(project: p)
FLOW.call(context)

Pipe

Pipes provide a way to describe business transactions in a stateless and reusable way. Let's create a few pipes from plain Ruby classes.

class PaymentPipe < Pipes::Pipe
  require_context :user        # flow will fail if precondition not met
  provide_context :transaction # flow will fail if postcondition not met

  def call
    result = PaymentService.create_transaction(user)
    add(transaction: result.transaction)
  end
end

Note how we've only had to implement the call method for the magic to start happening. When calling these objects you'd be using the class method call instead and passing a Pipes::Context objects to it. All unknown messages (like user) in two examples above are passed to the context which is an instance variable of every object inheriting from Pipes::Pipe.

Context

Each Pipe requires an instance Pipes::Context to be passed on .call invokation. It provides append-only data container for Pipes: you can add data to a context at any time using the add method but the same call will raise an error if you try to modify an existing key.

Made with ❤️ by code quest