Project

clomp

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Clomp gem provides a smooth, lightweight, productive and reusable way to build an operation using Railway Oriented Programing paradigm.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Clomp

CircleCI Issues Gem Version MIT license Maintainability Chat Code Triagers Badge

Clomp gem provides a smooth, lightweight, productive and reusable way to build an operation using Railway oriented programing paradigm. Clomp will give you an easy interface to complete your service operation. You can use it with any framework or plain ruby object.

Installation

Add this line to your application's Gemfile:

gem 'clomp'

And then execute:

$ bundle

Or install it yourself as:

$ gem install clomp

Usage

Build any service with the track! Add as many tracks as you want. tracks will be loaded sequentially. You can control success and failure state of any specific step.

Example application

You may check the following rails project for basic understanding. Clomp Usage Example

Clomp is completely framework independent agnostic framework. You can use it with any ruby frameworks and even with your raw ruby code.

Consider the following class:

class AnotherOperation < Clomp::Operation
  track :track_from_another_operation

  def track_from_another_operation(options)
    options[:hello_from_another_operation] = true
  end
end
    
class SingingOperation < Clomp::Operation
    # this block only executes on failure step! 
    # pass options to receive the operation states!   
    add_track :get_lyrics do |options|
      # we call this a failure state based block!
      options[:do_some_thing] = 10
    end
    
    add_track :get_instruments_ready
    
    add_track :start_signing
    
    # We can now share specific step from 
    # outsider operation
    share :track_from_another_operation, from: AnotherOperation # Or 'AnotherOperation'
    
    finally :receive_price #final step, wont execute after this step!
    
    def get_instruments_ready(options, params: , **)
      # do anything!
    end
    
    def get_lyrics(options, params: , **)
      params[:singer_name] = 'James' #mutate
    end
    
    def start_signing(options)
      puts options[:params]
    end
    
    def receive_price(options)
      puts "I am honored for this awesome price!"
    end
end
@result = SingingOperation[singer_name: 'Bass Baba']
@result.success? # => true
@result.failure? # => false

Trace the steps:

@result = SingingOperation[singer_name: 'Bass Baba']
@result.executed_tracks
"first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"

@result.to_s
"Clomp::Result > Successful: first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"

Configuration

You can set custom step name(s), custom fail, pass flow configuration globally and operation wise!

Clomp::Configuration.setup do |config|
# You can set as many step name as you want
config.custom_step_names =+ [:my_own_step_name]
end

Development

After checking out the repo, run bin/setup to install dependencies. 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 rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rubyrider/clomp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

Code of Conduct

Everyone interacting in the TheRailway project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.