Skip to content
DSL to build Pipelines with mountable Segments that process stuff
Branch: master
Clone or download
Latest commit 965684f Apr 19, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Add circleci config Mar 10, 2019
bin Setup guard for rspec Mar 10, 2019
lib Version bump Apr 19, 2019
.gitignore Simplistic pipeline version (#1) Apr 19, 2019
.ruby-version Add .ruby-version Feb 22, 2019
.travis.yml bundle gem nxt_pipeline Feb 22, 2019
Gemfile Add rspec_junit_formatter dependency for circleci Mar 10, 2019
Guardfile Setup guard for rspec Mar 10, 2019
LICENSE.txt bundle gem nxt_pipeline Feb 22, 2019 Simplistic pipeline version (#1) Apr 19, 2019
nxt_pipeline.gemspec Simplistic pipeline version (#1) Apr 19, 2019



nxt_pipeline provides a DSL to define pipeline classes which take an object and pass it through multiple steps which can read or modify the object.


Add this line to your application's Gemfile:

gem 'nxt_pipeline'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nxt_pipeline



First you probably want to configure a pipeline so that it can execute your steps. Therefore you want to define constructors for your steps. Constructors take a name as the first argument and step options as the second. All step options are being exposed by the step yielded to the constructor.

pipeline = do |p|
  # Add a named constructor that will be used to execute your steps later
  # All options that you pass in your step will be available through accessors in your constructor 
  p.constructor(:service, default: true) do |step, arg| arg).call
  p.constructor(:job) do |step, arg|
    step.job_class.perform_later(*arg) && arg

# Once a pipeline was created you can still configure it 
pipeline.constructor(:call) do |step, arg|

# same with block syntax 
# You can use this to split up execution from configuration  
pipeline.configure do |p|
 p.constructor(:call) do |step, arg|

Defining steps

Once your pipeline knows how to execute your steps you can add those.

pipeline.step :service, service_class: MyServiceClass, to_s: 'First step'
pipeline.step service_class: MyOtherServiceClass, to_s: 'Second step' 
# ^ Since service is the default step you don't have to specify it the step type each time
pipeline.step :job, job_class: MyJobClass # to_s is optional
pipeline.step :job, job_class: MyOtherJobClass

pipeline.step :step_name_for_better_log do |_, arg|
  # ...

pipeline.step to_s: 'This is the same as above' do |step, arg|
  # ... step.to_s => 'This is the same as above'

You can also define inline steps, meaning the block will be executed


You can then execute the steps with:

pipeline.execute('initial argument')

# Or run the steps directly using block syntax

pipeline.execute do |p|
  p.step :service, service_class: MyServiceClass, to_s: 'First step'
  p.step :service, service_class: MyOtherServiceClass, to_s: 'Second step'
  p.step :job, job_class: MyJobClass # to_s is optional
  p.step :job, job_class: MyOtherJobClass

You can also directly execute a pipeline with:

NxtPipeline::Pipeline.execute('initial argument') do |p|
  p.step do |_, arg|

Error callbacks

Apart from defining constructors and steps you can also define error callbacks. do |p|
  p.step do |_, arg|
  p.on_error MyCustomError do |step, arg, error|
    # First matching error callback will be executed!
  p.on_errors ArgumentError, KeyError do |step, arg, error|
    # First matching error callback will be executed!
  p.on_errors do |step, arg, error|
    # This will match all errors inheriting from StandardError


After checking out the repo, run bin/setup to install dependencies. Then, run bin/rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to

You can also run bin/guard to automatically run specs when files are saved.


Bug reports and pull requests are welcome on GitHub at


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

You can’t perform that action at this time.