ServiceIt Gem Version Build Status Code Climate Downloads License

Provide you a way to delegate responsibilities in your project using callables


Installation

Add this line to your application's Gemfile:

gem 'service_it', '~> 0.1.6'

And then execute:

$ bundle

Or install it yourself as:

$ gem install service_it

Generator

$ rails g service NAME

Usage

# app/services/foo.rb
class Foo < ServiceIt::Base
  def perform
    # here you can use params that became instance variables
  end
end

Call your service from anywhere

Foo.call(params)

Example

Simple example to change status of a transaction to complete

$ rails g service CompleteTransaction
# app/services/complete_transaction.rb
class CompleteTransaction < ServiceIt::Base
  def perform
    @transaction.update(:status, :complete)
  end
end
if CompleteTransaction.call(transaction: transaction)
  puts 'Transaction complete!'
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/iago-silva/service_it.

License

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