service_it 0.1.6 → 0.2.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/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +12 -0
- data/Gemfile.lock +36 -20
- data/README.md +24 -23
- data/Rakefile +0 -1
- data/lib/generators/rails/USAGE +8 -0
- data/lib/generators/rails/service_generator.rb +13 -0
- data/lib/generators/rails/templates/service.rb +4 -0
- data/lib/service_it/base.rb +41 -0
- data/lib/service_it.rb +1 -1
- data/service_it.gemspec +15 -11
- data/spec/service_it_spec.rb +10 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/test_classes.rb +5 -0
- metadata +35 -15
- data/bin/console +0 -13
- data/bin/setup +0 -8
- data/lib/service.rb +0 -39
- data/spec/service_spec.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1085eaf772f8657824e4495bdb6bb3ffe89362368fd922b7202ed8a7293966
|
4
|
+
data.tar.gz: d27ac5b1a0f82925d1d13849a9a556c84565d5427765a3ebf925971e3c1a627a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb0d062f6453045d96ef3549e01a8c6347eec3f4cf689b7fc96882f169171a2e8e7ac03634813fdec713ea3291ce475f0c867da06de6b96b6c89f4250bb0f09
|
7
|
+
data.tar.gz: 585172ed14df1120bc16d551f8336c9fbf4bb84f5355c488084a0cd012af64880ecbb1fd4eb8e3469da712167059c97a16b7ddaaafd104fdcb45bbbe76dec4ae
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,40 +1,56 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
service_it (0.
|
4
|
+
service_it (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
ast (2.4.0)
|
10
10
|
diff-lcs (1.3)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
rspec-
|
19
|
-
rspec-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
jaro_winkler (1.5.2)
|
12
|
+
parallel (1.17.0)
|
13
|
+
parser (2.6.2.1)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
psych (3.1.0)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rspec (3.8.0)
|
18
|
+
rspec-core (~> 3.8.0)
|
19
|
+
rspec-expectations (~> 3.8.0)
|
20
|
+
rspec-mocks (~> 3.8.0)
|
21
|
+
rspec-core (3.8.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-expectations (3.8.3)
|
23
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-mocks (3.
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-mocks (3.8.0)
|
26
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-support (3.
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-support (3.8.0)
|
30
|
+
rubocop (0.67.2)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.5, != 2.5.1.1)
|
34
|
+
psych (>= 3.1.0)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
ruby-progressbar (~> 1.7)
|
37
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
38
|
+
rubocop-performance (1.1.0)
|
39
|
+
rubocop (>= 0.67.0)
|
40
|
+
rubocop-rspec (1.32.0)
|
41
|
+
rubocop (>= 0.60.0)
|
42
|
+
ruby-progressbar (1.10.0)
|
43
|
+
unicode-display_width (1.5.0)
|
29
44
|
|
30
45
|
PLATFORMS
|
31
46
|
ruby
|
32
47
|
|
33
48
|
DEPENDENCIES
|
34
49
|
bundler
|
35
|
-
pry
|
36
|
-
rake
|
37
50
|
rspec
|
51
|
+
rubocop
|
52
|
+
rubocop-performance
|
53
|
+
rubocop-rspec
|
38
54
|
service_it!
|
39
55
|
|
40
56
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,11 +1,6 @@
|
|
1
|
-
# ServiceIt
|
1
|
+
# ServiceIt [](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it) [](https://rubygems.org/gems/service_it) [](http://opensource.org/licenses/MIT)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
<div align="center">
|
6
|
-
<img src="https://pbs.twimg.com/profile_images/1123677732/logo_avatar_large.png" height="250" width="250">
|
7
|
-
<p>Its main objective is to provide you a way to delegate responsibilities in your project</p>
|
8
|
-
</div>
|
3
|
+
Provide you a way to delegate responsibilities in your project using callables
|
9
4
|
|
10
5
|
<br/>
|
11
6
|
|
@@ -13,7 +8,7 @@
|
|
13
8
|
|
14
9
|
Add this line to your application's Gemfile:
|
15
10
|
|
16
|
-
gem 'service_it', '0.1.6'
|
11
|
+
gem 'service_it', '~> 0.1.6'
|
17
12
|
|
18
13
|
And then execute:
|
19
14
|
|
@@ -22,40 +17,46 @@ And then execute:
|
|
22
17
|
Or install it yourself as:
|
23
18
|
|
24
19
|
$ gem install service_it
|
20
|
+
|
21
|
+
## Generator
|
22
|
+
|
23
|
+
$ rails g service NAME
|
25
24
|
|
26
25
|
## Usage
|
27
26
|
|
28
|
-
Inherit your class of `Service` and implement `perform` method
|
29
27
|
```ruby
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# app/services/foo.rb
|
29
|
+
class Foo < ServiceIt::Base
|
30
|
+
def perform
|
31
|
+
# here you can use params that became instance variables
|
34
32
|
end
|
33
|
+
end
|
35
34
|
```
|
36
35
|
|
37
36
|
Call your service from anywhere
|
38
37
|
```ruby
|
39
|
-
|
38
|
+
Foo.call(params)
|
40
39
|
```
|
41
40
|
|
42
41
|
## Example
|
43
42
|
|
44
|
-
Simple example to change status of a
|
43
|
+
Simple example to change status of a _transaction_ to complete
|
44
|
+
|
45
|
+
$ rails g service CompleteTransaction
|
45
46
|
|
46
47
|
```ruby
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
48
|
+
# app/services/complete_transaction.rb
|
49
|
+
class CompleteTransaction < ServiceIt::Base
|
50
|
+
def perform
|
51
|
+
@transaction.update(:status, :complete)
|
52
52
|
end
|
53
|
+
end
|
53
54
|
```
|
54
55
|
|
55
56
|
```ruby
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
if CompleteTransaction.call(transaction: transaction)
|
58
|
+
puts 'Transaction complete!'
|
59
|
+
end
|
59
60
|
```
|
60
61
|
|
61
62
|
## Contributing
|
data/Rakefile
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
# Generates a service by command line
|
4
|
+
class ServiceGenerator < NamedBase
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
6
|
+
|
7
|
+
def create_service_file
|
8
|
+
template 'service.rb',
|
9
|
+
File.join('app/services', class_path, "#{file_name}.rb")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ServiceIt
|
2
|
+
# Inherit this class and implement perform method
|
3
|
+
#
|
4
|
+
# Documentation:
|
5
|
+
# https://github.com/iago-silva/service_it#usage
|
6
|
+
class Base
|
7
|
+
class << self
|
8
|
+
# Call your service
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
# Foo.call(arg1: 1, arg2: 2)
|
12
|
+
#
|
13
|
+
# Arguments:
|
14
|
+
# args: (Hash)
|
15
|
+
#
|
16
|
+
# Return:
|
17
|
+
# perform's return
|
18
|
+
def call(**args)
|
19
|
+
new_instance(args).perform
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def new_instance(args)
|
25
|
+
instance = new
|
26
|
+
|
27
|
+
args.each do |key, value|
|
28
|
+
instance.instance_variable_set("@#{key}", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
instance
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Implement this method to run your service
|
36
|
+
def perform
|
37
|
+
raise NotImplementedError,
|
38
|
+
"Please implement 'perform' method in your #{self.class.name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/service_it.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'service_it/base'
|
data/service_it.gemspec
CHANGED
@@ -3,24 +3,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'service_it'
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.2.0'
|
7
7
|
s.date = '2018-07-27'
|
8
8
|
s.authors = ['Iago Silva']
|
9
9
|
s.email = 'iago.silva@interage.in'
|
10
10
|
s.homepage = 'https://github.com/iago-silva/service_it'
|
11
11
|
s.license = 'MIT'
|
12
|
-
s.summary = '
|
13
|
-
|
14
|
-
s.description = '
|
15
|
-
|
12
|
+
s.summary = 'Simple gem for Rails that allows you to isolate a piece of
|
13
|
+
code and call it from anywhere'
|
14
|
+
s.description = 'Provide you a way to delegate responsibilities in your
|
15
|
+
project using callables'
|
16
16
|
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
|
20
|
-
|
17
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
18
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
21
|
|
22
22
|
s.add_development_dependency 'bundler'
|
23
|
-
s.add_development_dependency 'rake'
|
24
23
|
s.add_development_dependency 'rspec'
|
25
|
-
|
24
|
+
|
25
|
+
if RUBY_VERSION >= '2.2.0'
|
26
|
+
s.add_development_dependency 'rubocop'
|
27
|
+
s.add_development_dependency 'rubocop-performance'
|
28
|
+
s.add_development_dependency 'rubocop-rspec'
|
29
|
+
end
|
26
30
|
end
|
data/spec/spec_helper.rb
ADDED
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: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iago Silva
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,21 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rubocop
|
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'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop-rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -67,27 +81,31 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description: |-
|
70
|
-
|
71
|
-
|
84
|
+
Provide you a way to delegate responsibilities in your
|
85
|
+
project using callables
|
72
86
|
email: iago.silva@interage.in
|
73
|
-
executables:
|
74
|
-
- console
|
75
|
-
- setup
|
87
|
+
executables: []
|
76
88
|
extensions: []
|
77
89
|
extra_rdoc_files: []
|
78
90
|
files:
|
79
91
|
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
80
95
|
- Gemfile
|
81
96
|
- Gemfile.lock
|
82
97
|
- LICENSE.txt
|
83
98
|
- README.md
|
84
99
|
- Rakefile
|
85
|
-
-
|
86
|
-
-
|
87
|
-
- lib/service.rb
|
100
|
+
- lib/generators/rails/USAGE
|
101
|
+
- lib/generators/rails/service_generator.rb
|
102
|
+
- lib/generators/rails/templates/service.rb
|
88
103
|
- lib/service_it.rb
|
104
|
+
- lib/service_it/base.rb
|
89
105
|
- service_it.gemspec
|
90
|
-
- spec/
|
106
|
+
- spec/service_it_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/support/test_classes.rb
|
91
109
|
homepage: https://github.com/iago-silva/service_it
|
92
110
|
licenses:
|
93
111
|
- MIT
|
@@ -111,7 +129,9 @@ rubyforge_project:
|
|
111
129
|
rubygems_version: 2.7.3
|
112
130
|
signing_key:
|
113
131
|
specification_version: 4
|
114
|
-
summary:
|
132
|
+
summary: Simple gem for Rails that allows you to isolate a piece of code and call
|
115
133
|
it from anywhere
|
116
134
|
test_files:
|
117
|
-
- spec/
|
135
|
+
- spec/service_it_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
- spec/support/test_classes.rb
|
data/bin/console
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'service_it'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
require "pry"
|
10
|
-
Pry.start
|
11
|
-
|
12
|
-
require 'irb'
|
13
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/lib/service.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# Inherit this class and implement perform method
|
2
|
-
#
|
3
|
-
# Documentation:
|
4
|
-
# https://github.com/iago-silva/service_it#usage
|
5
|
-
class Service
|
6
|
-
class << self
|
7
|
-
# Call your service
|
8
|
-
#
|
9
|
-
# Example:
|
10
|
-
# ServiceIt.call(arg1: 1, arg2: 2)
|
11
|
-
#
|
12
|
-
# Arguments:
|
13
|
-
# args: (Hash)
|
14
|
-
#
|
15
|
-
# Return:
|
16
|
-
# perform's return
|
17
|
-
def call(**args)
|
18
|
-
new_instance(args).perform
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def new_instance(args)
|
24
|
-
instance = new
|
25
|
-
|
26
|
-
args.each do |key, value|
|
27
|
-
instance.instance_variable_set("@#{key}", value)
|
28
|
-
end
|
29
|
-
|
30
|
-
instance
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Implement this method to run your service
|
35
|
-
def perform
|
36
|
-
raise NotImplementedError,
|
37
|
-
"Please implement 'perform' method in your #{self.class.name}"
|
38
|
-
end
|
39
|
-
end
|
data/spec/service_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'service'
|
2
|
-
|
3
|
-
describe Service do
|
4
|
-
let(:result) { SayMyName.call(name: 'Heisenberg') }
|
5
|
-
|
6
|
-
before do
|
7
|
-
class SayMyName < Service
|
8
|
-
def perform
|
9
|
-
@name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'say Heisenberg' do
|
15
|
-
expect(result).to eq('Heisenberg')
|
16
|
-
end
|
17
|
-
end
|