Git Product home page Git Product logo

clomp's Introduction

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.

clomp's People

Contributors

crifat avatar rubyrider avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mezbahalam

clomp's Issues

Jump to Track

Will it be possible to add a feature where a developer can jump to a certain step by skipping steps in-between?
for example:

track :step_1
track :step_2
track :step_3

def step_1
    jump_to :step_3     # this will jump to step_3 and skip step_2
end

def step_2
    # Step 2 codes here
end

def step_3
    # Step 3 codes here
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.