action_logic 0.3.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yaml +18 -0
- data/Gemfile.lock +32 -35
- data/README.md +5 -6
- data/action_logic.gemspec +5 -5
- data/lib/action_logic/action_validation/presence_validation.rb +1 -1
- data/lib/action_logic/version.rb +1 -1
- data/spec/action_logic/{active_use_case_spec.rb → action_use_case_spec.rb} +1 -1
- data/spec/action_logic/configuration_spec.rb +1 -1
- data/spec/fixtures/tasks.rb +40 -0
- data/spec/fixtures/use_cases.rb +2 -42
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 332860b5c92213d9c2ed4b5e17b4016d002bd3d1a3aa36e5b7efe27c2bb4548e
|
4
|
+
data.tar.gz: 765f846bef16635c571b7d804c3674029adcb0d753c1a05284ac03a18af03459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9e4e43e85c0e6f1c2e8abf0386df61316d7bc66cf8a27343ac5e422e1db7d00ecd6a6f65b9ea2918a17c11be98df6e60adb363a3742d334d29eb6109f149d8f
|
7
|
+
data.tar.gz: dfa4be20e08233fbf8862649d1ff8b574c0ba50c9e535bf57b08d9f25ef6efa3ab0b08757519ed246c12eb0757e00c9ecd194562a1c905fd7f2ff1b8090cbb3b
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Test
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
os: [ubuntu-latest, macos-latest]
|
9
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
10
|
+
ruby: ['2.7', '3.0', '3.1']
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v3
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
18
|
+
- run: bundle exec rspec spec
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,51 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
action_logic (0.3.
|
4
|
+
action_logic (0.3.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
codecov (0.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
rspec-
|
25
|
-
|
26
|
-
rspec-core (3.8.0)
|
27
|
-
rspec-support (~> 3.8.0)
|
28
|
-
rspec-expectations (3.8.2)
|
9
|
+
codecov (0.6.0)
|
10
|
+
simplecov (>= 0.15, < 0.22)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
docile (1.4.0)
|
14
|
+
method_source (1.0.0)
|
15
|
+
pry (0.14.1)
|
16
|
+
coderay (~> 1.1)
|
17
|
+
method_source (~> 1.0)
|
18
|
+
rake (13.0.6)
|
19
|
+
rspec (3.11.0)
|
20
|
+
rspec-core (~> 3.11.0)
|
21
|
+
rspec-expectations (~> 3.11.0)
|
22
|
+
rspec-mocks (~> 3.11.0)
|
23
|
+
rspec-core (3.11.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-expectations (3.11.0)
|
29
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
-
rspec-mocks (3.
|
27
|
+
rspec-support (~> 3.11.0)
|
28
|
+
rspec-mocks (3.11.1)
|
32
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-support (3.
|
35
|
-
simplecov (0.
|
30
|
+
rspec-support (~> 3.11.0)
|
31
|
+
rspec-support (3.11.0)
|
32
|
+
simplecov (0.21.2)
|
36
33
|
docile (~> 1.1)
|
37
|
-
|
38
|
-
|
39
|
-
simplecov-html (0.
|
40
|
-
|
34
|
+
simplecov-html (~> 0.11)
|
35
|
+
simplecov_json_formatter (~> 0.1)
|
36
|
+
simplecov-html (0.12.3)
|
37
|
+
simplecov_json_formatter (0.1.4)
|
41
38
|
|
42
39
|
PLATFORMS
|
43
40
|
ruby
|
44
41
|
|
45
42
|
DEPENDENCIES
|
46
43
|
action_logic!
|
47
|
-
codecov (~> 0.
|
48
|
-
pry (~> 0.
|
49
|
-
rake (~>
|
50
|
-
rspec (~> 3.
|
51
|
-
simplecov (~> 0.
|
44
|
+
codecov (~> 0.6.0)
|
45
|
+
pry (~> 0.14.1)
|
46
|
+
rake (~> 13.0.6)
|
47
|
+
rspec (~> 3.11)
|
48
|
+
simplecov (~> 0.21.2)
|
52
49
|
|
53
50
|
BUNDLED WITH
|
54
51
|
1.17.2
|
data/README.md
CHANGED
@@ -58,12 +58,11 @@ includes an item that your e-commerce store no longer stocks? What happens if an
|
|
58
58
|
you add more and more logic to that controller action.
|
59
59
|
|
60
60
|
What once was a simple controller action designed with only the happy path of a successful checkout in mind has now become 100 lines long with 5 to 10 levels
|
61
|
-
of nested if statements.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
Where does it end you wonder?
|
61
|
+
of nested if statements. You think on it for awhile and consider not only the technical challenges of refactoring this code, but you'd also like to make this code
|
62
|
+
reusable and modular. You want this code to be easy to test and easy to maintain. You want to honor the SOLID principles by writing classes that are singularly focused
|
63
|
+
and easy to extend. You reason these new classes should only have to change if the business logic they execute changes. You see that there are relationships between the
|
64
|
+
entities and you see the possibility of abstractions that allow entities of similar types to interact nicely with each other. You begin thinking about interfaces and the
|
65
|
+
Liskov Substitution Principle, and eventually your mind turns towards domains and data modeling. Where does it end you wonder?
|
67
66
|
|
68
67
|
But you remember your team. It's a team of people all wanting to do their best, and represent a variety of backgrounds and experiences. Each person has varying degress of familiarity
|
69
68
|
with different types of abstractions and approaches, and you wonder what abstractions might be as easy to work with for a new developer as they are for an experienced developer?
|
data/action_logic.gemspec
CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.date = '2018-12-17'
|
18
18
|
s.description = 'Provides common interfaces for validating and abstracting business logic'
|
19
19
|
|
20
|
-
s.add_development_dependency("rspec", "~> 3.
|
21
|
-
s.add_development_dependency("pry", "~> 0.
|
22
|
-
s.add_development_dependency("rake", "~>
|
23
|
-
s.add_development_dependency("simplecov", "~> 0.
|
24
|
-
s.add_development_dependency("codecov", "~> 0.
|
20
|
+
s.add_development_dependency("rspec", "~> 3.11")
|
21
|
+
s.add_development_dependency("pry", "~> 0.14.1")
|
22
|
+
s.add_development_dependency("rake", "~> 13.0.6")
|
23
|
+
s.add_development_dependency("simplecov", "~> 0.21.2")
|
24
|
+
s.add_development_dependency("codecov", "~> 0.6.0")
|
25
25
|
end
|
@@ -13,7 +13,7 @@ module ActionLogic
|
|
13
13
|
|
14
14
|
def self.presence_errors(validation_rules, context)
|
15
15
|
validation_rules.reduce([]) do |error_collection, (expected_attribute, expected_validation)|
|
16
|
-
next unless expected_validation[:presence]
|
16
|
+
next error_collection unless expected_validation[:presence]
|
17
17
|
error_collection << error_message(expected_attribute, expected_validation, context)
|
18
18
|
error_collection
|
19
19
|
end || []
|
data/lib/action_logic/version.rb
CHANGED
@@ -164,7 +164,7 @@ module ActionLogic
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it "raises error if type validation is not satisfied" do
|
167
|
-
expect { ValidateBeforeMixedTypeAndPresenceUseCase.execute(odd_integer_test:
|
167
|
+
expect { ValidateBeforeMixedTypeAndPresenceUseCase.execute(odd_integer_test: "String", string_test: 15) }.to \
|
168
168
|
raise_error(ActionLogic::AttributeTypeError)
|
169
169
|
end
|
170
170
|
|
@@ -63,7 +63,7 @@ describe ActionLogic do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "uses a custom benchmark handler if one is provided" do
|
66
|
-
custom_benchmark_handler = -> {
|
66
|
+
custom_benchmark_handler = -> {}
|
67
67
|
|
68
68
|
described_class.configure do |config|
|
69
69
|
config.benchmark_handler = custom_benchmark_handler
|
data/spec/fixtures/tasks.rb
CHANGED
@@ -284,4 +284,44 @@ class HaltTestTask
|
|
284
284
|
context.halt!(Constants::HALT_MESSAGE)
|
285
285
|
end
|
286
286
|
end
|
287
|
+
|
288
|
+
class UseCaseTestTask1
|
289
|
+
include ActionLogic::ActionTask
|
290
|
+
|
291
|
+
def call
|
292
|
+
context.first = "first"
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
class UseCaseTestTask2
|
297
|
+
include ActionLogic::ActionTask
|
298
|
+
|
299
|
+
def call
|
300
|
+
context.second = "second"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
class UseCaseTestTask3
|
305
|
+
include ActionLogic::ActionTask
|
306
|
+
|
307
|
+
def call
|
308
|
+
context.third = "third"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
class UseCaseFailureTestTask
|
313
|
+
include ActionLogic::ActionTask
|
314
|
+
|
315
|
+
def call
|
316
|
+
context.fail!(Constants::FAILURE_MESSAGE)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class UseCaseHaltTestTask
|
321
|
+
include ActionLogic::ActionTask
|
322
|
+
|
323
|
+
def call
|
324
|
+
context.halt!(Constants::HALT_MESSAGE)
|
325
|
+
end
|
326
|
+
end
|
287
327
|
# :nocov:
|
data/spec/fixtures/use_cases.rb
CHANGED
@@ -192,8 +192,8 @@ end
|
|
192
192
|
class ValidateBeforeMixedTypeAndPresenceUseCase
|
193
193
|
include ActionLogic::ActionUseCase
|
194
194
|
|
195
|
-
validates_before odd_integer_test: { presence: ->(i) { i % 2 != 0 } },
|
196
|
-
string_test: {
|
195
|
+
validates_before odd_integer_test: { type: Integer, presence: ->(i) { i % 2 != 0 }, type: Integer },
|
196
|
+
string_test: { presence: false, type: String }
|
197
197
|
|
198
198
|
def call
|
199
199
|
end
|
@@ -392,44 +392,4 @@ class HaltTestUseCase
|
|
392
392
|
UseCaseTestTask3]
|
393
393
|
end
|
394
394
|
end
|
395
|
-
|
396
|
-
class UseCaseTestTask1
|
397
|
-
include ActionLogic::ActionTask
|
398
|
-
|
399
|
-
def call
|
400
|
-
context.first = "first"
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
class UseCaseTestTask2
|
405
|
-
include ActionLogic::ActionTask
|
406
|
-
|
407
|
-
def call
|
408
|
-
context.second = "second"
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
class UseCaseTestTask3
|
413
|
-
include ActionLogic::ActionTask
|
414
|
-
|
415
|
-
def call
|
416
|
-
context.third = "third"
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
class UseCaseFailureTestTask
|
421
|
-
include ActionLogic::ActionTask
|
422
|
-
|
423
|
-
def call
|
424
|
-
context.fail!(Constants::FAILURE_MESSAGE)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
class UseCaseHaltTestTask
|
429
|
-
include ActionLogic::ActionTask
|
430
|
-
|
431
|
-
def call
|
432
|
-
context.halt!(Constants::HALT_MESSAGE)
|
433
|
-
end
|
434
|
-
end
|
435
395
|
# :nocov:
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Winfrey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-12-17 00:00:00.000000000 Z
|
@@ -16,76 +16,77 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.11'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.14.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.14.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 13.0.6
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 13.0.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.21.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.21.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: codecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.6.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.6.0
|
83
83
|
description: Provides common interfaces for validating and abstracting business logic
|
84
84
|
email: rick.winfrey@gmail.com
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
|
+
- ".github/workflows/test.yaml"
|
89
90
|
- ".gitignore"
|
90
91
|
- ".travis.yml"
|
91
92
|
- CODE_OF_CONDUCT.md
|
@@ -121,7 +122,7 @@ files:
|
|
121
122
|
- spec/action_logic/action_context_spec.rb
|
122
123
|
- spec/action_logic/action_coordinator_spec.rb
|
123
124
|
- spec/action_logic/action_task_spec.rb
|
124
|
-
- spec/action_logic/
|
125
|
+
- spec/action_logic/action_use_case_spec.rb
|
125
126
|
- spec/action_logic/configuration_spec.rb
|
126
127
|
- spec/fixtures/constants.rb
|
127
128
|
- spec/fixtures/coordinators.rb
|
@@ -133,7 +134,7 @@ homepage: https://github.com/rewinfrey/action_logic
|
|
133
134
|
licenses:
|
134
135
|
- MIT
|
135
136
|
metadata: {}
|
136
|
-
post_install_message:
|
137
|
+
post_install_message:
|
137
138
|
rdoc_options: []
|
138
139
|
require_paths:
|
139
140
|
- lib
|
@@ -148,9 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
|
-
|
152
|
-
|
153
|
-
signing_key:
|
152
|
+
rubygems_version: 3.3.7
|
153
|
+
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Business logic abstraction
|
156
156
|
test_files:
|
@@ -158,7 +158,7 @@ test_files:
|
|
158
158
|
- spec/action_logic/action_context_spec.rb
|
159
159
|
- spec/action_logic/action_coordinator_spec.rb
|
160
160
|
- spec/action_logic/action_task_spec.rb
|
161
|
-
- spec/action_logic/
|
161
|
+
- spec/action_logic/action_use_case_spec.rb
|
162
162
|
- spec/action_logic/configuration_spec.rb
|
163
163
|
- spec/fixtures/constants.rb
|
164
164
|
- spec/fixtures/coordinators.rb
|