Project

service_it

0.0
No commit activity in last 3 years
No release in over 3 years
Service objects are a holy grail to keep your controllers and models slim and readable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 0.13.1
= 3.10.0
= 1.5.1
 Project Readme

ServiceIt

Gem Version Build Status Code Climate

Facilitate the creation of Service Objects, providing the basic and enough to have a complete one and letting you free to use on your own way.

  • ServiceIt
    • Installation
    • With Bundler
    • Rails Generator
    • Usage
    • Example

Installation

$ gem install service_it

With Bundler

Add this line to your Gemfile:

gem 'service_it', '~> 2.0.0'

And then execute:

$ bundle

Rails Generator

You can use Rails generator to create a Service

$ rails g service NAME

This will create:

├── app
    ├── services
        └── name.rb

Usage

class Foo < ServiceIt::Base
  def perform
    # put your logic here
    # you can use params that became variables
  end
end

Call your service from anywhere (controllers, models, migrations...)

Foo.call(foo: foo, bar: bar)

Example

# app/services/release_post.rb
class ReleasePost < ServiceIt::Base
  def perform
    post.prepare_to_release
    post.update(released_at: Date.current)
  end
end
ReleasePost.call(post: @post)