service_it 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +69 -28
- data/lib/service_it/base.rb +6 -0
- data/lib/service_it/version.rb +1 -1
- data/spec/service_it_spec.rb +10 -2
- data/spec/spec_helper.rb +7 -0
- data/spec/support/test_classes.rb +6 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd3980a2426fb7838e0ae392a4a12a79ea81d0a385eae6fd5b53e3147f02f11
|
4
|
+
data.tar.gz: 4bef1fceed1af00155948b3399da13cee01b24ca65ad77dbfb8a6ac92df3165f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017467fd53746def423e3456badf5a0ac6e7ff896489738b9015a5b83cca12718a13355de5489f6b28282bc05ab7cb85d7b1266a12ceedc50c8db724c4f06a9d
|
7
|
+
data.tar.gz: ce95f14007a1dbbcd1aae0c1186e6c79852f037f4e4fb4fa5c8d8cefd371855cbb6c9b45e96648a7988af46256c8284c5b35ff59e22217fb6e39c84bf237f94a
|
data/README.md
CHANGED
@@ -1,71 +1,112 @@
|
|
1
|
-
[](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it)
|
2
|
-
|
3
1
|
# ServiceIt
|
2
|
+
[](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it/test_coverage)
|
4
3
|
|
5
|
-
[
|
6
|
-
|
7
|
-
|
4
|
+
- [ServiceIt](#serviceit)
|
5
|
+
- [Installation](#installation)
|
6
|
+
- [With Bundler](#with-bundler)
|
7
|
+
- [Rails Generator](#rails-generator)
|
8
|
+
- [Usage](#usage)
|
9
|
+
- [Example](#example)
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
11
13
|
$ gem install service_it
|
12
|
-
|
14
|
+
|
13
15
|
## With Bundler
|
14
16
|
|
15
17
|
Add this line to your `Gemfile`:
|
16
18
|
|
17
|
-
gem 'service_it', '~> 0.
|
19
|
+
gem 'service_it', '~> 1.0.0'
|
18
20
|
|
19
21
|
And then execute:
|
20
22
|
|
21
23
|
$ bundle
|
22
|
-
|
23
|
-
##
|
24
|
+
|
25
|
+
## Rails Generator
|
24
26
|
|
25
27
|
You can use Rails generator to create a `Service`
|
26
28
|
|
27
29
|
$ rails g service NAME
|
28
30
|
|
31
|
+
This will create:
|
32
|
+
|
33
|
+
```
|
34
|
+
├── app
|
35
|
+
├── services
|
36
|
+
└── name.rb
|
37
|
+
```
|
38
|
+
|
29
39
|
## Usage
|
30
40
|
|
31
41
|
```ruby
|
32
42
|
class Foo < ServiceIt::Base
|
33
43
|
def perform
|
34
|
-
#
|
44
|
+
# put your logic here
|
45
|
+
# you can use params that became variables
|
35
46
|
end
|
36
47
|
end
|
37
48
|
```
|
38
49
|
|
39
50
|
Call your service from anywhere
|
51
|
+
|
40
52
|
```ruby
|
41
|
-
Foo.call(
|
42
|
-
```
|
53
|
+
Foo.call(foo: foo, bar: bar)
|
54
|
+
```
|
43
55
|
|
44
|
-
## Example
|
56
|
+
## Example
|
45
57
|
|
46
|
-
Simple example
|
58
|
+
Simple example to release a _POST_
|
47
59
|
|
48
|
-
|
60
|
+
* Before
|
49
61
|
|
50
62
|
```ruby
|
51
|
-
# app/
|
52
|
-
class
|
53
|
-
|
54
|
-
|
63
|
+
# app/controllers/post_releases_controller.rb
|
64
|
+
class PostReleasesController < ApplicationController
|
65
|
+
|
66
|
+
# [...]
|
67
|
+
|
68
|
+
def update
|
69
|
+
@post.prepare_to_release # <--
|
70
|
+
if @post.update(released_at: Date.current) # <--
|
71
|
+
# [...]
|
72
|
+
else
|
73
|
+
# [...]
|
74
|
+
end
|
55
75
|
end
|
76
|
+
|
77
|
+
# [...]
|
78
|
+
|
56
79
|
end
|
57
|
-
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
* After
|
58
84
|
|
59
85
|
```ruby
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
```
|
86
|
+
# app/controllers/post_releases_controller.rb
|
87
|
+
class PostReleasesController < ApplicationController
|
64
88
|
|
65
|
-
|
89
|
+
# [...]
|
66
90
|
|
67
|
-
|
91
|
+
def update
|
92
|
+
if ReleasePost.call(post: @post) # <--
|
93
|
+
# [...]
|
94
|
+
else
|
95
|
+
# [...]
|
96
|
+
end
|
97
|
+
end
|
68
98
|
|
69
|
-
|
99
|
+
# [...]
|
70
100
|
|
71
|
-
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
# app/services/release_post.rb
|
106
|
+
class ReleasePost < ServiceIt::Base
|
107
|
+
def perform
|
108
|
+
post.prepare_to_release
|
109
|
+
post.update(released_at: Date.current)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
data/lib/service_it/base.rb
CHANGED
data/lib/service_it/version.rb
CHANGED
data/spec/service_it_spec.rb
CHANGED
@@ -3,10 +3,18 @@ require 'spec_helper'
|
|
3
3
|
describe ServiceIt do
|
4
4
|
describe SayMyName do
|
5
5
|
let(:name) { 'Heisenberg' }
|
6
|
-
let(:
|
6
|
+
let(:call) { SayMyName.call(name: 'Heisenberg') }
|
7
7
|
|
8
8
|
it 'says Heisenberg' do
|
9
|
-
expect(
|
9
|
+
expect(call).to eq(name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when perform method is not defined' do
|
14
|
+
it 'raises an NotImplementedError exception' do
|
15
|
+
expect do
|
16
|
+
MissedPerformService.call
|
17
|
+
end.to raise_error(NotImplementedError)
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iago Silva
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: |-
|
42
56
|
Service objects are a holy grail to keep your controllers and
|
43
57
|
models slim and readable
|
@@ -76,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
90
|
version: '0'
|
77
91
|
requirements: []
|
78
92
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.7.
|
93
|
+
rubygems_version: 2.7.9
|
80
94
|
signing_key:
|
81
95
|
specification_version: 4
|
82
96
|
summary: Simple gem to keep your controllers and models slim and readable
|