ServicePacker
This gem is for decoupling your logic from models, some actions in a system warrant a Service Object to encapsulate their operation(e.g. notifications, emails, feedbacks, etc). Service packer provides a series of methods to standardize the process of many common behaviors.
Installation
Add this line to your application's Gemfile:
gem 'service_packer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install service_packer
Usage
Here is a list with all the available behaviors, listed in the same order in which they will get called during the respective operations.
The operation life cycle
- validation
- action
- callback
A simple example:
class Service < ServicePacker::Base
def initialize(ride)
@ride = ride
end
setup :send, :params => [:driver] do
validation_define do |driver|
unless ride.may_send?
ride.errors.add(:base, :cannot_be_assigned)
end
ride
end
action_define do |driver|
ride.send(driver)
end
callback_define do |driver|
Notifier.send_to(driver, "New ride")
end
end
attr_reader :ride
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/FX-HAO/service_packer. 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.