Pipes provide a Unix-like way to chain business objects (interactors) in Ruby.
To start using Pipes, add the library to your Gemfile and run bundle install.
gem'codequest_pipes'FLOW=Projects::Match | # NOTE: each of the elements must inherit fromProjects::Validate | # Pipes::Pipe!Projects::UpdatePayment |
Projects::SaveWithReportcontext=Pipes::Context.new(project: p)FLOW.call(context)Pipes provide a way to describe business transactions in a stateless and reusable way. Let's create a few pipes from plain Ruby classes.
classPaymentPipe < Pipes::Piperequire_context:user# flow will fail if precondition not metprovide_context:transaction# flow will fail if postcondition not metdefcallresult=PaymentService.create_transaction(user)add(transaction: result.transaction)endendNote 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.
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