lite-command 1.4.1 → 1.5.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/.rubocop.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +57 -58
- data/README.md +64 -51
- data/lib/lite/command/complex.rb +9 -7
- data/lib/lite/command/exceptions.rb +0 -1
- data/lib/lite/command/extensions/errors.rb +7 -7
- data/lib/lite/command/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86f89baebccec981ab697dbe02cc25cae4f143f881b4a765719147eb832b9ae5
|
|
4
|
+
data.tar.gz: 39b8e5010d1b4c107be5b6f2396e86730f85c2d115a8ee6f3e8585daf8754543
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dab8d3533ec7efa114f6119dff6ec6e172c1de828a8bcfe9f968939d227e98bfc3f6607f5d0de621a49cdd0edf17dbe4b893739720a9ae768d8eae9f8de6331a
|
|
7
|
+
data.tar.gz: e116e71fe7c0c895579e7d8bcc22b444c3cb681fe634cc435fb286ca5917bb6bb96a6c88848a3aa6e34c20a16efe0956605188448ef408b8cc0746637b1047ae
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.5.0] - 2022-04-19
|
|
10
|
+
### Changed
|
|
11
|
+
- Update docs
|
|
12
|
+
- Rename internal variables for more clarity
|
|
13
|
+
- Improved spec checkers
|
|
14
|
+
|
|
9
15
|
## [1.4.1] - 2021-09-04
|
|
10
16
|
### Changed
|
|
11
17
|
- Fixed nil issue with `assign_and_return!`
|
data/Gemfile.lock
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lite-command (1.
|
|
4
|
+
lite-command (1.5.0)
|
|
5
5
|
lite-errors
|
|
6
6
|
lite-memoize
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (
|
|
12
|
-
actionview (=
|
|
13
|
-
activesupport (=
|
|
14
|
-
rack (~> 2.0, >= 2.0
|
|
11
|
+
actionpack (7.0.2.3)
|
|
12
|
+
actionview (= 7.0.2.3)
|
|
13
|
+
activesupport (= 7.0.2.3)
|
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
|
15
15
|
rack-test (>= 0.6.3)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
-
actionview (
|
|
19
|
-
activesupport (=
|
|
18
|
+
actionview (7.0.2.3)
|
|
19
|
+
activesupport (= 7.0.2.3)
|
|
20
20
|
builder (~> 3.1)
|
|
21
21
|
erubi (~> 1.4)
|
|
22
22
|
rails-dom-testing (~> 2.0)
|
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
-
activemodel (
|
|
25
|
-
activesupport (=
|
|
26
|
-
activerecord (
|
|
27
|
-
activemodel (=
|
|
28
|
-
activesupport (=
|
|
29
|
-
activesupport (
|
|
24
|
+
activemodel (7.0.2.3)
|
|
25
|
+
activesupport (= 7.0.2.3)
|
|
26
|
+
activerecord (7.0.2.3)
|
|
27
|
+
activemodel (= 7.0.2.3)
|
|
28
|
+
activesupport (= 7.0.2.3)
|
|
29
|
+
activesupport (7.0.2.3)
|
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
31
31
|
i18n (>= 1.6, < 2)
|
|
32
32
|
minitest (>= 5.1)
|
|
33
33
|
tzinfo (~> 2.0)
|
|
34
|
-
zeitwerk (~> 2.3)
|
|
35
34
|
ast (2.4.2)
|
|
36
35
|
builder (3.2.4)
|
|
37
36
|
colorize (0.8.1)
|
|
38
|
-
concurrent-ruby (1.1.
|
|
37
|
+
concurrent-ruby (1.1.10)
|
|
39
38
|
crass (1.0.6)
|
|
40
39
|
database_cleaner (2.0.1)
|
|
41
40
|
database_cleaner-active_record (~> 2.0.0)
|
|
@@ -43,7 +42,7 @@ GEM
|
|
|
43
42
|
activerecord (>= 5.a)
|
|
44
43
|
database_cleaner-core (~> 2.0.0)
|
|
45
44
|
database_cleaner-core (2.0.1)
|
|
46
|
-
diff-lcs (1.
|
|
45
|
+
diff-lcs (1.5.0)
|
|
47
46
|
erubi (1.10.0)
|
|
48
47
|
fasterer (0.9.0)
|
|
49
48
|
colorize (~> 0.7)
|
|
@@ -51,23 +50,23 @@ GEM
|
|
|
51
50
|
generator_spec (0.9.4)
|
|
52
51
|
activesupport (>= 3.0.0)
|
|
53
52
|
railties (>= 3.0.0)
|
|
54
|
-
i18n (1.
|
|
53
|
+
i18n (1.10.0)
|
|
55
54
|
concurrent-ruby (~> 1.0)
|
|
56
55
|
lite-errors (1.2.1)
|
|
57
56
|
lite-memoize (1.1.1)
|
|
58
|
-
loofah (2.
|
|
57
|
+
loofah (2.16.0)
|
|
59
58
|
crass (~> 1.0.2)
|
|
60
59
|
nokogiri (>= 1.5.9)
|
|
61
60
|
method_source (1.0.0)
|
|
62
|
-
mini_portile2 (2.
|
|
63
|
-
minitest (5.
|
|
64
|
-
nokogiri (1.
|
|
65
|
-
mini_portile2 (~> 2.
|
|
61
|
+
mini_portile2 (2.8.0)
|
|
62
|
+
minitest (5.15.0)
|
|
63
|
+
nokogiri (1.13.4)
|
|
64
|
+
mini_portile2 (~> 2.8.0)
|
|
66
65
|
racc (~> 1.4)
|
|
67
|
-
parallel (1.
|
|
68
|
-
parser (3.
|
|
66
|
+
parallel (1.22.1)
|
|
67
|
+
parser (3.1.2.0)
|
|
69
68
|
ast (~> 2.4.1)
|
|
70
|
-
racc (1.
|
|
69
|
+
racc (1.6.0)
|
|
71
70
|
rack (2.2.3)
|
|
72
71
|
rack-test (1.1.0)
|
|
73
72
|
rack (>= 1.0, < 3)
|
|
@@ -76,58 +75,58 @@ GEM
|
|
|
76
75
|
nokogiri (>= 1.6)
|
|
77
76
|
rails-html-sanitizer (1.4.2)
|
|
78
77
|
loofah (~> 2.3)
|
|
79
|
-
railties (
|
|
80
|
-
actionpack (=
|
|
81
|
-
activesupport (=
|
|
78
|
+
railties (7.0.2.3)
|
|
79
|
+
actionpack (= 7.0.2.3)
|
|
80
|
+
activesupport (= 7.0.2.3)
|
|
82
81
|
method_source
|
|
83
|
-
rake (>=
|
|
82
|
+
rake (>= 12.2)
|
|
84
83
|
thor (~> 1.0)
|
|
85
|
-
|
|
84
|
+
zeitwerk (~> 2.5)
|
|
85
|
+
rainbow (3.1.1)
|
|
86
86
|
rake (13.0.6)
|
|
87
|
-
regexp_parser (2.
|
|
87
|
+
regexp_parser (2.3.0)
|
|
88
88
|
rexml (3.2.5)
|
|
89
|
-
rspec (3.
|
|
90
|
-
rspec-core (~> 3.
|
|
91
|
-
rspec-expectations (~> 3.
|
|
92
|
-
rspec-mocks (~> 3.
|
|
93
|
-
rspec-core (3.
|
|
94
|
-
rspec-support (~> 3.
|
|
95
|
-
rspec-expectations (3.
|
|
89
|
+
rspec (3.11.0)
|
|
90
|
+
rspec-core (~> 3.11.0)
|
|
91
|
+
rspec-expectations (~> 3.11.0)
|
|
92
|
+
rspec-mocks (~> 3.11.0)
|
|
93
|
+
rspec-core (3.11.0)
|
|
94
|
+
rspec-support (~> 3.11.0)
|
|
95
|
+
rspec-expectations (3.11.0)
|
|
96
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
97
|
-
rspec-support (~> 3.
|
|
98
|
-
rspec-mocks (3.
|
|
97
|
+
rspec-support (~> 3.11.0)
|
|
98
|
+
rspec-mocks (3.11.1)
|
|
99
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
100
|
-
rspec-support (~> 3.
|
|
101
|
-
rspec-support (3.
|
|
102
|
-
rubocop (1.
|
|
100
|
+
rspec-support (~> 3.11.0)
|
|
101
|
+
rspec-support (3.11.0)
|
|
102
|
+
rubocop (1.27.0)
|
|
103
103
|
parallel (~> 1.10)
|
|
104
|
-
parser (>= 3.
|
|
104
|
+
parser (>= 3.1.0.0)
|
|
105
105
|
rainbow (>= 2.2.2, < 4.0)
|
|
106
106
|
regexp_parser (>= 1.8, < 3.0)
|
|
107
107
|
rexml
|
|
108
|
-
rubocop-ast (>= 1.
|
|
108
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
|
109
109
|
ruby-progressbar (~> 1.7)
|
|
110
110
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
111
|
-
rubocop-ast (1.
|
|
112
|
-
parser (>= 3.
|
|
113
|
-
rubocop-performance (1.
|
|
111
|
+
rubocop-ast (1.17.0)
|
|
112
|
+
parser (>= 3.1.1.0)
|
|
113
|
+
rubocop-performance (1.13.3)
|
|
114
114
|
rubocop (>= 1.7.0, < 2.0)
|
|
115
115
|
rubocop-ast (>= 0.4.0)
|
|
116
116
|
rubocop-rake (0.6.0)
|
|
117
117
|
rubocop (~> 1.0)
|
|
118
|
-
rubocop-rspec (2.
|
|
119
|
-
rubocop (~> 1.
|
|
120
|
-
rubocop-ast (>= 1.1.0)
|
|
118
|
+
rubocop-rspec (2.10.0)
|
|
119
|
+
rubocop (~> 1.19)
|
|
121
120
|
ruby-progressbar (1.11.0)
|
|
122
|
-
ruby_parser (3.
|
|
123
|
-
sexp_processor (~> 4.
|
|
124
|
-
sexp_processor (4.
|
|
121
|
+
ruby_parser (3.19.1)
|
|
122
|
+
sexp_processor (~> 4.16)
|
|
123
|
+
sexp_processor (4.16.1)
|
|
125
124
|
sqlite3 (1.4.2)
|
|
126
|
-
thor (1.1
|
|
125
|
+
thor (1.2.1)
|
|
127
126
|
tzinfo (2.0.4)
|
|
128
127
|
concurrent-ruby (~> 1.0)
|
|
129
|
-
unicode-display_width (2.
|
|
130
|
-
zeitwerk (2.4
|
|
128
|
+
unicode-display_width (2.1.0)
|
|
129
|
+
zeitwerk (2.5.4)
|
|
131
130
|
|
|
132
131
|
PLATFORMS
|
|
133
132
|
ruby
|
|
@@ -148,4 +147,4 @@ DEPENDENCIES
|
|
|
148
147
|
sqlite3
|
|
149
148
|
|
|
150
149
|
BUNDLED WITH
|
|
151
|
-
2.
|
|
150
|
+
2.3.11
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://travis-ci.org/drexed/lite-command)
|
|
5
5
|
|
|
6
6
|
Lite::Command provides an API for building simple and complex command based service objects.
|
|
7
|
-
It provides
|
|
7
|
+
It provides extensions for handling errors and memoization to improve your object workflow productivity.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -44,41 +44,49 @@ fallback to `Lite::Command::Complex`.
|
|
|
44
44
|
|
|
45
45
|
## Simple
|
|
46
46
|
|
|
47
|
-
Simple commands
|
|
48
|
-
|
|
47
|
+
Simple commands are a traditional command service call objects.
|
|
48
|
+
It only exposes a `call` method that returns a value.
|
|
49
|
+
|
|
50
|
+
**Setup**
|
|
49
51
|
|
|
50
52
|
```ruby
|
|
51
|
-
class
|
|
53
|
+
class CalculatePower < Lite::Command::Simple
|
|
52
54
|
|
|
53
|
-
# NOTE: This class method is required
|
|
54
|
-
def self.execute(
|
|
55
|
-
|
|
55
|
+
# NOTE: This `execute` class method is required to use with call
|
|
56
|
+
def self.execute(a, b)
|
|
57
|
+
a**b
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
end
|
|
59
61
|
```
|
|
60
62
|
|
|
61
|
-
**
|
|
63
|
+
**Callers**
|
|
62
64
|
|
|
63
65
|
```ruby
|
|
64
|
-
|
|
66
|
+
CalculatePower.execute(2, 2) #=> 4
|
|
67
|
+
|
|
68
|
+
# - or -
|
|
69
|
+
|
|
70
|
+
CalculatePower.call(2, 3) #=> 8
|
|
65
71
|
```
|
|
66
72
|
|
|
67
73
|
## Complex
|
|
68
74
|
|
|
69
|
-
Complex commands
|
|
70
|
-
|
|
75
|
+
Complex commands are powerful command service call objects.
|
|
76
|
+
It can be extended to use error, memoization, and propagation mixins.
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
**Setup**
|
|
73
79
|
|
|
74
80
|
```ruby
|
|
75
81
|
class SearchMovies < Lite::Command::Complex
|
|
76
82
|
|
|
83
|
+
attr_reader :name
|
|
84
|
+
|
|
77
85
|
def initialize(name)
|
|
78
86
|
@name = name
|
|
79
87
|
end
|
|
80
88
|
|
|
81
|
-
# NOTE: This instance method is required
|
|
89
|
+
# NOTE: This `execute` instance method is required to use with call
|
|
82
90
|
def execute
|
|
83
91
|
{ generate_fingerprint => movies_by_name }
|
|
84
92
|
end
|
|
@@ -86,7 +94,7 @@ class SearchMovies < Lite::Command::Complex
|
|
|
86
94
|
private
|
|
87
95
|
|
|
88
96
|
def movies_by_name
|
|
89
|
-
HTTP.get("http://movies.com?title=#{
|
|
97
|
+
HTTP.get("http://movies.com?title=#{name}")
|
|
90
98
|
end
|
|
91
99
|
|
|
92
100
|
def generate_fingerprint
|
|
@@ -99,6 +107,10 @@ end
|
|
|
99
107
|
**Caller**
|
|
100
108
|
|
|
101
109
|
```ruby
|
|
110
|
+
SearchMovies.execute('Toy Story') #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
111
|
+
|
|
112
|
+
# - or -
|
|
113
|
+
|
|
102
114
|
command = SearchMovies.new('Toy Story')
|
|
103
115
|
command.called? #=> false
|
|
104
116
|
command.call #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
@@ -109,12 +121,6 @@ command.called? #=> true
|
|
|
109
121
|
command = SearchMovies.call('Toy Story')
|
|
110
122
|
command.called? #=> true
|
|
111
123
|
command.call #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
112
|
-
|
|
113
|
-
# - or -
|
|
114
|
-
|
|
115
|
-
# Useful when you are not using the Errors mixin as its a one time access call.
|
|
116
|
-
# Very similar to the simple command builder.
|
|
117
|
-
SearchMovies.execute('Toy Story') #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
118
124
|
```
|
|
119
125
|
|
|
120
126
|
**Result**
|
|
@@ -126,35 +132,33 @@ command.result #=> nil
|
|
|
126
132
|
command.call #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
127
133
|
command.result #=> { 'fingerprint_1' => [ 'Toy Story 1', ... ] }
|
|
128
134
|
|
|
129
|
-
command.recall! #=> Clears the call
|
|
135
|
+
command.recall! #=> Clears the `call`, `cache`, `errors` variables and then re-performs the call
|
|
130
136
|
command.result #=> { 'fingerprint_2' => [ 'Toy Story 2', ... ] }
|
|
131
137
|
```
|
|
132
138
|
|
|
133
139
|
## Procedure
|
|
134
140
|
|
|
135
|
-
Procedures run a collection of commands. It uses the the complex procedure API
|
|
141
|
+
Procedures are used to run a collection of commands. It uses the the complex procedure API
|
|
136
142
|
so it has access to all the methods. The `execute` method is already defined to
|
|
137
143
|
handle most common procedure steps. It can be use directly or subclassed.
|
|
138
144
|
|
|
145
|
+
**Setup**
|
|
146
|
+
|
|
139
147
|
```ruby
|
|
140
148
|
class SearchChannels < Lite::Command::Procedure; end
|
|
149
|
+
```
|
|
141
150
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
EspnChannel.new(current_station),
|
|
145
|
-
MtvChannel.new
|
|
146
|
-
)
|
|
151
|
+
```ruby
|
|
152
|
+
commands = [DisneyChannel.new, EspnChannel.new(current_station), MtvChannel.new]
|
|
147
153
|
|
|
154
|
+
procedure = SearchChannels.call(*commands)
|
|
148
155
|
procedure.result #=> ['disney: #3', 'espn: #59', 'mtv: #212']
|
|
149
156
|
procedure.steps #=> [<DisneyChannel @result="...">, <EspnChannel @result="...">, <MtvChannel @result="...">]
|
|
150
157
|
|
|
151
|
-
#
|
|
152
|
-
procedure = SearchChannels.new(
|
|
153
|
-
DisneyChannel.new,
|
|
154
|
-
ErrorChannel.new(current_station),
|
|
155
|
-
MtvChannel.new
|
|
156
|
-
)
|
|
158
|
+
# - or -
|
|
157
159
|
|
|
160
|
+
# If the errors extension is added you can stop the procedure at first failure.
|
|
161
|
+
procedure = SearchChannels.new(*commands)
|
|
158
162
|
procedure.exit_on_failure = true
|
|
159
163
|
procedure.call
|
|
160
164
|
procedure.result #=> ['disney: #3']
|
|
@@ -169,6 +173,8 @@ Extend complex (and procedures) base command with any of the following extension
|
|
|
169
173
|
|
|
170
174
|
Learn more about using [Lite::Errors](https://github.com/drexed/lite-errors)
|
|
171
175
|
|
|
176
|
+
**Setup**
|
|
177
|
+
|
|
172
178
|
```ruby
|
|
173
179
|
class SearchMovies < Lite::Command::Complex
|
|
174
180
|
include Lite::Command::Extensions::Errors
|
|
@@ -177,28 +183,21 @@ class SearchMovies < Lite::Command::Complex
|
|
|
177
183
|
|
|
178
184
|
private
|
|
179
185
|
|
|
180
|
-
# Add a
|
|
186
|
+
# Add a explicit and/or exception errors to the error pool
|
|
181
187
|
def generate_fingerprint
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
if movies_by_name.nil?
|
|
189
|
+
errors.add(:fingerprint, 'invalid md5 request value')
|
|
190
|
+
else
|
|
191
|
+
Digest::MD5.hexdigest(movies_by_name)
|
|
192
|
+
end
|
|
193
|
+
rescue ArgumentError => exception
|
|
194
|
+
merge_exception!(exception, key: :custom_error_key)
|
|
186
195
|
end
|
|
187
196
|
|
|
188
197
|
end
|
|
189
198
|
```
|
|
190
199
|
|
|
191
|
-
**Callers**
|
|
192
|
-
|
|
193
|
-
```ruby
|
|
194
|
-
# Useful for controllers or actions that depend on states.
|
|
195
|
-
SearchMovies.perform('Toy Story') do |result, success, failure|
|
|
196
|
-
success.call { redirect_to(movie_path, notice: "Movie can be found at: #{result}") }
|
|
197
|
-
failure.call { redirect_to(root_path, notice: "Movie cannot be found at: #{result}") }
|
|
198
|
-
end
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
**Methods**
|
|
200
|
+
**Instance Callers**
|
|
202
201
|
|
|
203
202
|
```ruby
|
|
204
203
|
command = SearchMovies.call('Toy Story')
|
|
@@ -220,6 +219,16 @@ command.merge_errors!(command_2)
|
|
|
220
219
|
user_model.merge_errors!(command, direction: :to)
|
|
221
220
|
```
|
|
222
221
|
|
|
222
|
+
**Block Callers**
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
# Useful for controllers or actions that depend on states.
|
|
226
|
+
SearchMovies.perform('Toy Story') do |result, success, failure|
|
|
227
|
+
success.call { redirect_to(movie_path, notice: "Movie can be found at: #{result}") }
|
|
228
|
+
failure.call { redirect_to(root_path, notice: "Movie cannot be found at: #{result}") }
|
|
229
|
+
end
|
|
230
|
+
```
|
|
231
|
+
|
|
223
232
|
### Propagation (optional)
|
|
224
233
|
|
|
225
234
|
Propagation methods help you perform an action on an object. If successful is
|
|
@@ -232,6 +241,8 @@ propagation methods are:
|
|
|
232
241
|
- `archive_and_return!(object)` (if using Lite::Archive)
|
|
233
242
|
- `save_and_return!(object)`
|
|
234
243
|
|
|
244
|
+
**Setup**
|
|
245
|
+
|
|
235
246
|
```ruby
|
|
236
247
|
class SearchMovies < Lite::Command::Complex
|
|
237
248
|
include Lite::Command::Extensions::Errors
|
|
@@ -250,6 +261,8 @@ end
|
|
|
250
261
|
|
|
251
262
|
Learn more about using [Lite::Memoize](https://github.com/drexed/lite-memoize)
|
|
252
263
|
|
|
264
|
+
**Setup**
|
|
265
|
+
|
|
253
266
|
```ruby
|
|
254
267
|
class SearchMovies < Lite::Command::Complex
|
|
255
268
|
include Lite::Command::Extensions::Memoize
|
|
@@ -262,7 +275,7 @@ class SearchMovies < Lite::Command::Complex
|
|
|
262
275
|
# Subsequent method calls gets the cached value
|
|
263
276
|
# This saves you the extra external HTTP.get call
|
|
264
277
|
def movies_by_name
|
|
265
|
-
cache.memoize { HTTP.get("http://movies.com?title=#{
|
|
278
|
+
cache.memoize { HTTP.get("http://movies.com?title=#{name}") }
|
|
266
279
|
end
|
|
267
280
|
|
|
268
281
|
# Gets the value in the cache
|
|
@@ -273,7 +286,7 @@ class SearchMovies < Lite::Command::Complex
|
|
|
273
286
|
end
|
|
274
287
|
```
|
|
275
288
|
|
|
276
|
-
**
|
|
289
|
+
**Callers**
|
|
277
290
|
|
|
278
291
|
```ruby
|
|
279
292
|
command = SearchMovies.call('Toy Story')
|
data/lib/lite/command/complex.rb
CHANGED
|
@@ -7,16 +7,17 @@ module Lite
|
|
|
7
7
|
class << self
|
|
8
8
|
|
|
9
9
|
def call(*args, **kwargs, &block)
|
|
10
|
-
|
|
11
|
-
raise Lite::Command::NotImplementedError unless klass.respond_to?(:execute)
|
|
10
|
+
instance = new(*args, **kwargs, &block)
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
raise Lite::Command::NotImplementedError unless instance.respond_to?(:execute)
|
|
13
|
+
|
|
14
|
+
instance.call
|
|
15
|
+
instance
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def execute(*args, **kwargs, &block)
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
instance = call(*args, **kwargs, &block)
|
|
20
|
+
instance.result
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
end
|
|
@@ -29,6 +30,7 @@ module Lite
|
|
|
29
30
|
|
|
30
31
|
def call
|
|
31
32
|
raise Lite::Command::NotImplementedError unless defined?(execute)
|
|
33
|
+
|
|
32
34
|
return @result if called?
|
|
33
35
|
|
|
34
36
|
@called = true
|
|
@@ -41,7 +43,7 @@ module Lite
|
|
|
41
43
|
|
|
42
44
|
def recall!
|
|
43
45
|
@called = false
|
|
44
|
-
%i[cache errors].each { |
|
|
46
|
+
%i[cache errors].each { |method_name| send(method_name).clear if respond_to?(method_name) }
|
|
45
47
|
call
|
|
46
48
|
end
|
|
47
49
|
|
|
@@ -10,12 +10,12 @@ module Lite
|
|
|
10
10
|
module ClassMethods
|
|
11
11
|
|
|
12
12
|
def perform(*args, **kwargs, &block)
|
|
13
|
-
|
|
13
|
+
instance = call(*args, **kwargs, &block)
|
|
14
14
|
|
|
15
|
-
if
|
|
16
|
-
yield(
|
|
15
|
+
if instance.success?
|
|
16
|
+
yield(instance.result, Lite::Command::Success, Lite::Command::Failure)
|
|
17
17
|
else
|
|
18
|
-
yield(
|
|
18
|
+
yield(instance.result, Lite::Command::Failure, Lite::Command::Success)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -45,10 +45,10 @@ module Lite
|
|
|
45
45
|
called? && errored?
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
def merge_errors!(
|
|
48
|
+
def merge_errors!(instance, direction: :from)
|
|
49
49
|
case direction
|
|
50
|
-
when :from then errors.merge!(
|
|
51
|
-
when :to then
|
|
50
|
+
when :from then errors.merge!(instance.errors)
|
|
51
|
+
when :to then instance.errors.merge!(errors)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
nil
|
data/lib/lite/command/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lite-command
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juan Gomez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lite-errors
|
|
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
262
262
|
- !ruby/object:Gem::Version
|
|
263
263
|
version: '0'
|
|
264
264
|
requirements: []
|
|
265
|
-
rubygems_version: 3.
|
|
265
|
+
rubygems_version: 3.3.11
|
|
266
266
|
signing_key:
|
|
267
267
|
specification_version: 4
|
|
268
268
|
summary: Ruby Command based framework (aka service objects)
|