simple_service 2.1.4 → 2.1.6
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/.github/workflows/build_master.yml +41 -0
- data/README.md +22 -24
- data/checksums/simple_service-2.1.4.gem.sha512 +1 -0
- data/lib/simple_service/result.rb +1 -1
- data/lib/simple_service/version.rb +1 -1
- data/simple_service.gemspec +9 -2
- data/spec/simple_service_spec.rb +46 -26
- data/spec/support/multiple_outcome_calls.rb +16 -0
- metadata +14 -22
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 407aa35e8ec13960f5cc0509d5e1152b5f94fed9bf7d035aa20e759b27e4de80
|
|
4
|
+
data.tar.gz: 9fbaaf4c5afbf37dd68814032312e3a1d8b98e0a1f5d511c111c2679f881296e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4f17ce95877a995c8b0b48a12b57c1147360115bd1b94b365c30a8a618bfa591197d66f107594923cf71cd81ec80e38b6101be28a93967bf6b3b96adfe69927
|
|
7
|
+
data.tar.gz: 61e3058fe33d2294255fa1933901146f417199c45b83fdb428d6d7c835df78d2e222b25cce2862025b1dcd1b5ececf698abb885adb2c70ca4e0411c76b89c0f8
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Build Master
|
|
2
|
+
|
|
3
|
+
env:
|
|
4
|
+
CC_TEST_REPORTER_URL: https://codeclimate.com/downloads/test-reporter/test-reporter-0.7.0-linux-amd64
|
|
5
|
+
CC_TEST_REPORTER_ID: ${{ secrets.SIMPLE_SERVICE_CODECLIMATE_ID }}
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
push:
|
|
11
|
+
branches:
|
|
12
|
+
- master
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
os: [ubuntu-latest]
|
|
19
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
|
20
|
+
ruby: ["2.7.0", "3.2.2"]
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v3
|
|
24
|
+
- uses: ruby/setup-ruby@v1
|
|
25
|
+
with:
|
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
|
27
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: |
|
|
31
|
+
gem install bundler -v 2.4.14
|
|
32
|
+
bundle install --jobs 3 --retry 3
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: RUBYOPT="-E UTF-8" bundle exec rake
|
|
36
|
+
|
|
37
|
+
- name: Code Climate Test Reporter
|
|
38
|
+
uses: aktions/codeclimate-test-reporter@v1
|
|
39
|
+
with:
|
|
40
|
+
codeclimate-test-reporter-id: ${{ secrets.SIMPLE_SERVICE_CODECLIMATE_ID }}
|
|
41
|
+
command: after-build
|
data/README.md
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
# SimpleService
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/simple_service)
|
|
4
|
-
[](https://travis-ci.org/jspillers/simple_service)
|
|
7
|
-
<!---->
|
|
4
|
+
[](https://codeclimate.com/github/jspillers/simple_service/maintainability)
|
|
5
|
+
[](https://codeclimate.com/github/jspillers/simple_service/test_coverage)
|
|
8
6
|
|
|
9
7
|
SimpleService facilitates the creation of Ruby service objects into highly discreet, reusable,
|
|
10
|
-
and composable units of business logic. The core concept of SimpleService is the definition of
|
|
11
|
-
"Command" objects/methods. Commands are very small classes or methods that perform exactly one task.
|
|
8
|
+
and composable units of business logic. The core concept of SimpleService is the definition of
|
|
9
|
+
"Command" objects/methods. Commands are very small classes or methods that perform exactly one task.
|
|
12
10
|
When properly designed, these command objects can be composited together or even nested to create
|
|
13
11
|
complex flows.
|
|
14
12
|
|
|
15
13
|
# 2.0.0 update notes
|
|
16
14
|
|
|
17
|
-
This update is a major refactor from previous 1.x.x versions. After revisiting this codebase I decided that
|
|
15
|
+
This update is a major refactor from previous 1.x.x versions. After revisiting this codebase I decided that
|
|
18
16
|
I needed to make SimpleService actually simple in both use and implementation. The gem has now been paired down
|
|
19
17
|
to about 150 lines of code.
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
- All functionality is added to your service class via module inclusion instead of inheritance
|
|
20
|
+
- The concept of an Organizer has been removed
|
|
21
|
+
- The DSL for defining interfaces has been removed in favor of simple keyword arguments
|
|
22
|
+
- `#success` or `#failure` must be called within each command or call method
|
|
23
|
+
- Services are always invoked via the class method `.call`. Previously you could use either `#call` or `.call`.
|
|
26
24
|
|
|
27
25
|
## Installation
|
|
28
26
|
|
|
@@ -40,10 +38,10 @@ Or install it yourself as:
|
|
|
40
38
|
|
|
41
39
|
# Setup and Basic Usage:
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
- load the gem
|
|
42
|
+
- include the SimpleService module into your service object class
|
|
43
|
+
- define one or more comamnds that it will perform, must accept either keyword arguments or a hash argument
|
|
44
|
+
- call `#success` or `#failure` with any values you wish to pass along to the next command (or wish to return if it is the last command)
|
|
47
45
|
|
|
48
46
|
```ruby
|
|
49
47
|
require 'rubygems'
|
|
@@ -100,7 +98,7 @@ You can also use ClassNames as commands and to organize them into other files. I
|
|
|
100
98
|
defined and no other commands are defined via `command` or `commands` then SimpleService will
|
|
101
99
|
automatically use `#call` as the default command
|
|
102
100
|
|
|
103
|
-
```ruby
|
|
101
|
+
```ruby
|
|
104
102
|
require 'rubygems'
|
|
105
103
|
require 'simple_service'
|
|
106
104
|
|
|
@@ -144,7 +142,7 @@ result.value #=> {something: 'went wrong'}
|
|
|
144
142
|
```
|
|
145
143
|
|
|
146
144
|
If you would like your service to process an enumerable you can override `.call`
|
|
147
|
-
on your service object. Invoking `#super` in your definition and passing along
|
|
145
|
+
on your service object. Invoking `#super` in your definition and passing along
|
|
148
146
|
the appropriate arguments will allow your command chain to proceed as normal, but
|
|
149
147
|
called multiple times via a loop. The Result object returned from each call to `#super`
|
|
150
148
|
can be passed in as an argument to the next iteration or you can collect the result objects
|
|
@@ -162,11 +160,11 @@ class LoopingService
|
|
|
162
160
|
def self.call(count:)
|
|
163
161
|
count = kwargs
|
|
164
162
|
|
|
165
|
-
# In this example the result object from super overwrites
|
|
166
|
-
# the previous result/initial args. You could also capture
|
|
163
|
+
# In this example the result object from super overwrites
|
|
164
|
+
# the previous result/initial args. You could also capture
|
|
167
165
|
# results in an array or hash for further manipulation.
|
|
168
166
|
# If you do not need to do anything with the result object
|
|
169
|
-
# then there is no need to assign it back to anything.
|
|
167
|
+
# then there is no need to assign it back to anything.
|
|
170
168
|
3.times do
|
|
171
169
|
count = super(count)
|
|
172
170
|
end
|
|
@@ -179,13 +177,13 @@ class LoopingService
|
|
|
179
177
|
end
|
|
180
178
|
end
|
|
181
179
|
|
|
182
|
-
result = LoopingService.call(count: 0)
|
|
180
|
+
result = LoopingService.call(count: 0)
|
|
183
181
|
result.is_a?(SimpleService::Result) #=> true
|
|
184
182
|
result.value #=> {count: 3}
|
|
185
183
|
```
|
|
186
184
|
|
|
187
|
-
If you are using this with a Rails app, placing top level services in
|
|
188
|
-
`app/services/` and all nested commands in `app/services/commands/` is
|
|
185
|
+
If you are using this with a Rails app, placing top level services in
|
|
186
|
+
`app/services/` and all nested commands in `app/services/commands/` is
|
|
189
187
|
recommended. Even if not using rails, a similar structure also works well.
|
|
190
188
|
|
|
191
189
|
## Contributing
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cb567a382f07efd13ccbb083e1f8b876aaae4d752b188fd8d7fc42cc0fdba86d5c6d051187e4422aa3d9e5a7d9ad2db4789142fced9cd6cd3d6b08a99f3d40d3
|
data/simple_service.gemspec
CHANGED
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.version = SimpleService::VERSION
|
|
9
9
|
spec.authors = ['Jarrod Spillers']
|
|
10
10
|
spec.email = ['jarrod@stacktact.com']
|
|
11
|
-
spec.description = %q{A minimal service object composer
|
|
11
|
+
spec.description = %q{A minimal service object composer and orchestrator}
|
|
12
12
|
spec.summary = spec.description
|
|
13
13
|
spec.homepage = 'https://github.com/jspillers/simple_service'
|
|
14
14
|
spec.license = 'MIT'
|
|
@@ -18,10 +18,17 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ['lib']
|
|
20
20
|
|
|
21
|
+
spec.metadata = {
|
|
22
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
|
23
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
|
|
24
|
+
"documentation_uri" => spec.homepage.to_s,
|
|
25
|
+
"homepage_uri" => spec.homepage.to_s,
|
|
26
|
+
"source_code_uri" => spec.homepage.to_s,
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
spec.add_development_dependency 'bundler'
|
|
22
30
|
spec.add_development_dependency 'rake', '~> 12.3.3'
|
|
23
31
|
spec.add_development_dependency 'rspec', '~> 3.12.0'
|
|
24
32
|
spec.add_development_dependency 'pry', '~> 0.14.2'
|
|
25
33
|
spec.add_development_dependency 'simplecov'
|
|
26
|
-
spec.add_development_dependency 'codeclimate-test-reporter'
|
|
27
34
|
end
|
data/spec/simple_service_spec.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
require_relative 'support/basic_service'
|
|
3
3
|
require_relative 'support/looping_service'
|
|
4
4
|
require_relative 'support/empty_service'
|
|
5
|
+
require_relative 'support/multiple_outcome_calls'
|
|
5
6
|
|
|
6
7
|
RSpec.describe SimpleService do
|
|
7
8
|
|
|
@@ -87,31 +88,50 @@ RSpec.describe SimpleService do
|
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
context 'record commands' do
|
|
91
|
+
it 'value refects only one outcome call per command' do
|
|
92
|
+
result = MultipleOutcomeCalls.call(params.merge(foo: 'foo', bar: 'bar'))
|
|
93
|
+
expect(result.value).to eq(foo: 'FOO', bar: 'BAR')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'recorded commands has only one outcome call per command' do
|
|
97
|
+
result = MultipleOutcomeCalls.call(params.merge(foo: 'foo', bar: 'bar'))
|
|
98
|
+
expect(result.recorded_commands).to eq(Set.new([
|
|
99
|
+
{
|
|
100
|
+
class_name: 'MultipleOutcomeCalls',
|
|
101
|
+
command_name: :command_one,
|
|
102
|
+
success: true,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
class_name: 'MultipleOutcomeCalls',
|
|
106
|
+
command_name: :command_two,
|
|
107
|
+
success: true,
|
|
108
|
+
},
|
|
109
|
+
]))
|
|
110
|
+
end
|
|
111
|
+
|
|
90
112
|
it 'records normal command execution' do
|
|
91
|
-
expect(result.recorded_commands).to eq(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
]
|
|
114
|
-
)
|
|
113
|
+
expect(result.recorded_commands).to eq(Set.new([
|
|
114
|
+
{
|
|
115
|
+
class_name: 'BasicService',
|
|
116
|
+
command_name: :upcase_foo,
|
|
117
|
+
success: true,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
class_name: 'BasicService',
|
|
121
|
+
command_name: :upcase_bar,
|
|
122
|
+
success: true,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
class_name: 'ModifyFooBar',
|
|
126
|
+
command_name: :call,
|
|
127
|
+
success: true,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
class_name: 'CombineFooBar',
|
|
131
|
+
command_name: :call,
|
|
132
|
+
success: true,
|
|
133
|
+
},
|
|
134
|
+
]))
|
|
115
135
|
end
|
|
116
136
|
|
|
117
137
|
it 'records verbose command execution' do
|
|
@@ -119,7 +139,7 @@ RSpec.describe SimpleService do
|
|
|
119
139
|
config.verbose_tracking = true
|
|
120
140
|
end
|
|
121
141
|
|
|
122
|
-
expect(result.recorded_commands).to eq(
|
|
142
|
+
expect(result.recorded_commands).to eq(Set.new(
|
|
123
143
|
[
|
|
124
144
|
{
|
|
125
145
|
class_name: 'BasicService',
|
|
@@ -181,7 +201,7 @@ RSpec.describe SimpleService do
|
|
|
181
201
|
},
|
|
182
202
|
},
|
|
183
203
|
]
|
|
184
|
-
)
|
|
204
|
+
))
|
|
185
205
|
end
|
|
186
206
|
end
|
|
187
207
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class MultipleOutcomeCalls
|
|
2
|
+
include SimpleService
|
|
3
|
+
|
|
4
|
+
commands :command_one,
|
|
5
|
+
:command_two,
|
|
6
|
+
|
|
7
|
+
def command_one(**kwargs)
|
|
8
|
+
success(kwargs.merge(foo: kwargs[:foo].capitalize))
|
|
9
|
+
success(kwargs.merge(foo: kwargs[:foo].upcase))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def command_two(**kwargs)
|
|
13
|
+
success(bar: kwargs[:bar].capitalize)
|
|
14
|
+
success(foo: kwargs[:foo].upcase, bar: kwargs[:bar].upcase)
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_service
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jarrod Spillers
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-08-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -80,36 +80,22 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
-
|
|
84
|
-
name: codeclimate-test-reporter
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
|
-
description: A minimal service object composer with support for individual commands
|
|
98
|
-
and top level organizer objects
|
|
83
|
+
description: A minimal service object composer and orchestrator
|
|
99
84
|
email:
|
|
100
85
|
- jarrod@stacktact.com
|
|
101
86
|
executables: []
|
|
102
87
|
extensions: []
|
|
103
88
|
extra_rdoc_files: []
|
|
104
89
|
files:
|
|
90
|
+
- ".github/workflows/build_master.yml"
|
|
105
91
|
- ".gitignore"
|
|
106
92
|
- ".rspec"
|
|
107
|
-
- ".travis.yml"
|
|
108
93
|
- Gemfile
|
|
109
94
|
- LICENSE
|
|
110
95
|
- LICENSE.txt
|
|
111
96
|
- README.md
|
|
112
97
|
- Rakefile
|
|
98
|
+
- checksums/simple_service-2.1.4.gem.sha512
|
|
113
99
|
- lib/simple_service.rb
|
|
114
100
|
- lib/simple_service/configuration.rb
|
|
115
101
|
- lib/simple_service/result.rb
|
|
@@ -122,10 +108,16 @@ files:
|
|
|
122
108
|
- spec/support/empty_service.rb
|
|
123
109
|
- spec/support/looping_service.rb
|
|
124
110
|
- spec/support/modify_foo_bar.rb
|
|
111
|
+
- spec/support/multiple_outcome_calls.rb
|
|
125
112
|
homepage: https://github.com/jspillers/simple_service
|
|
126
113
|
licenses:
|
|
127
114
|
- MIT
|
|
128
|
-
metadata:
|
|
115
|
+
metadata:
|
|
116
|
+
bug_tracker_uri: https://github.com/jspillers/simple_service/issues
|
|
117
|
+
changelog_uri: https://github.com/jspillers/simple_service/blob/main/CHANGELOG.md
|
|
118
|
+
documentation_uri: https://github.com/jspillers/simple_service
|
|
119
|
+
homepage_uri: https://github.com/jspillers/simple_service
|
|
120
|
+
source_code_uri: https://github.com/jspillers/simple_service
|
|
129
121
|
post_install_message:
|
|
130
122
|
rdoc_options: []
|
|
131
123
|
require_paths:
|
|
@@ -144,8 +136,7 @@ requirements: []
|
|
|
144
136
|
rubygems_version: 3.4.10
|
|
145
137
|
signing_key:
|
|
146
138
|
specification_version: 4
|
|
147
|
-
summary: A minimal service object composer
|
|
148
|
-
top level organizer objects
|
|
139
|
+
summary: A minimal service object composer and orchestrator
|
|
149
140
|
test_files:
|
|
150
141
|
- spec/simple_service_spec.rb
|
|
151
142
|
- spec/spec_helper.rb
|
|
@@ -154,3 +145,4 @@ test_files:
|
|
|
154
145
|
- spec/support/empty_service.rb
|
|
155
146
|
- spec/support/looping_service.rb
|
|
156
147
|
- spec/support/modify_foo_bar.rb
|
|
148
|
+
- spec/support/multiple_outcome_calls.rb
|