Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iago-silva/service_it
[Service Objects] Simple gem to keep your controllers and models slim and readable
https://github.com/iago-silva/service_it
gem rails rails-generator ruby ruby-on-rails service service-object
Last synced: 2 months ago
JSON representation
[Service Objects] Simple gem to keep your controllers and models slim and readable
- Host: GitHub
- URL: https://github.com/iago-silva/service_it
- Owner: iago-silva
- License: mit
- Created: 2019-04-21T17:49:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-03T16:40:45.000Z (over 3 years ago)
- Last Synced: 2024-09-30T09:41:18.466Z (3 months ago)
- Topics: gem, rails, rails-generator, ruby, ruby-on-rails, service, service-object
- Language: Ruby
- Homepage:
- Size: 139 KB
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ServiceIt
[![Gem Version](https://badge.fury.io/rb/service_it.svg)](https://badge.fury.io/rb/service_it)
[![Build Status](https://travis-ci.org/iago-silva/service_it.svg?branch=master)](https://travis-ci.org/iago-silva/service_it)
[![Code Climate](https://codeclimate.com/github/iago-silva/service_it.png)](https://codeclimate.com/github/iago-silva/service_it)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](#serviceit)
- [Installation](#installation)
- [With Bundler](#with-bundler)
- [Rails Generator](#rails-generator)
- [Usage](#usage)
- [Example](#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
```ruby
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...)
```ruby
Foo.call(foo: foo, bar: bar)
```## Example
```ruby
# app/services/release_post.rb
class ReleasePost < ServiceIt::Base
def perform
post.prepare_to_release
post.update(released_at: Date.current)
end
end
``````ruby
ReleasePost.call(post: @post)
```