lite-command 1.0.6 → 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/.rubocop.yml +14 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile.lock +76 -59
- data/README.md +65 -18
- data/lib/generators/rails/USAGE +0 -1
- data/lib/generators/rails/command_generator.rb +0 -7
- data/lib/generators/rails/templates/command.rb.tt +1 -1
- data/lib/lite/command.rb +2 -3
- data/lib/lite/command/extensions/propagation.rb +31 -0
- data/lib/lite/command/procedure.rb +34 -0
- data/lib/lite/command/version.rb +1 -1
- data/lite-command.gemspec +3 -0
- metadata +51 -10
- data/lib/generators/lite/command/install_generator.rb +0 -17
- data/lib/generators/lite/command/templates/install.rb +0 -4
- data/lib/generators/rails/templates/spec.rb.tt +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1832d3973ed0b408d8c4c11d6fb0e53ab9184080bc5eca37d99c69ec7a29c09c
|
|
4
|
+
data.tar.gz: a7f5dc00b4b00587a8f4f9115637d02f69ad7218112b1a1b066a994e477be93d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 235acc1478d53eeb81f16419a3c53eaa1ca743f472872508e433d4031b1a5fbc19f6a1cdee11d1fa7f35b44031ef8cd6d36510646e5c8cf58748f8866e365bd3
|
|
7
|
+
data.tar.gz: eebb89a36eac24e2836c5742a78039c575bda0915696588da8cdbd1c0e4a40af976e6ab8412ab1e2d36790d422191aa2440f0d2fbdb3341b5c17d3679b32f8ac
|
data/.rubocop.yml
CHANGED
|
@@ -2,11 +2,14 @@ require:
|
|
|
2
2
|
- rubocop-performance
|
|
3
3
|
- rubocop-rspec
|
|
4
4
|
AllCops:
|
|
5
|
-
TargetRubyVersion: 2.
|
|
5
|
+
TargetRubyVersion: 2.7
|
|
6
|
+
NewCops: enable
|
|
6
7
|
DisplayCopNames: true
|
|
7
8
|
DisplayStyleGuide: true
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
Gemspec/RequiredRubyVersion:
|
|
10
|
+
Enabled: false
|
|
11
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
|
12
|
+
Enabled: true
|
|
10
13
|
Layout/EmptyLinesAroundBlockBody:
|
|
11
14
|
Exclude:
|
|
12
15
|
- 'spec/**/**/*'
|
|
@@ -14,6 +17,14 @@ Layout/EmptyLinesAroundClassBody:
|
|
|
14
17
|
EnforcedStyle: empty_lines_except_namespace
|
|
15
18
|
Layout/EmptyLinesAroundModuleBody:
|
|
16
19
|
EnforcedStyle: empty_lines_except_namespace
|
|
20
|
+
Layout/LineLength:
|
|
21
|
+
Max: 100
|
|
22
|
+
Layout/SpaceAroundMethodCallOperator:
|
|
23
|
+
Enabled: true
|
|
24
|
+
Lint/RaiseException:
|
|
25
|
+
Enabled: true
|
|
26
|
+
Lint/StructNewOverride:
|
|
27
|
+
Enabled: true
|
|
17
28
|
Metrics/BlockLength:
|
|
18
29
|
Exclude:
|
|
19
30
|
- 'spec/**/**/*'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.0] - 2019-06-06
|
|
10
|
+
### Added
|
|
11
|
+
- Added procedure support for running multiple commands
|
|
12
|
+
|
|
13
|
+
## [1.0.10] - 2019-12-21
|
|
14
|
+
### Added
|
|
15
|
+
- Added Ruby 2.7 support
|
|
16
|
+
### Removed
|
|
17
|
+
- Removed generator empty directory check
|
|
18
|
+
|
|
19
|
+
## [1.0.9] - 2019-12-20
|
|
20
|
+
### Removed
|
|
21
|
+
- Removed lite-command generator
|
|
22
|
+
- Removed rspec file from rails generator
|
|
23
|
+
|
|
24
|
+
## [1.0.8] - 2019-09-16
|
|
25
|
+
### Changed
|
|
26
|
+
- Changed create propagation to check errors instead of persistence
|
|
27
|
+
|
|
28
|
+
## [1.0.7] - 2019-09-12
|
|
29
|
+
### Added
|
|
30
|
+
- Add propagation mixin
|
|
31
|
+
|
|
9
32
|
## [1.0.6] - 2019-09-07
|
|
10
33
|
### Added
|
|
11
34
|
- Raise error when class `call` if class doesn't respond_to `execute`
|
data/Gemfile.lock
CHANGED
|
@@ -1,117 +1,133 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lite-command (1.0
|
|
4
|
+
lite-command (1.1.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 (6.0.
|
|
12
|
-
actionview (= 6.0.
|
|
13
|
-
activesupport (= 6.0.
|
|
14
|
-
rack (~> 2.0)
|
|
11
|
+
actionpack (6.0.3.4)
|
|
12
|
+
actionview (= 6.0.3.4)
|
|
13
|
+
activesupport (= 6.0.3.4)
|
|
14
|
+
rack (~> 2.0, >= 2.0.8)
|
|
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 (6.0.
|
|
19
|
-
activesupport (= 6.0.
|
|
18
|
+
actionview (6.0.3.4)
|
|
19
|
+
activesupport (= 6.0.3.4)
|
|
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
|
-
|
|
24
|
+
activemodel (6.0.3.4)
|
|
25
|
+
activesupport (= 6.0.3.4)
|
|
26
|
+
activerecord (6.0.3.4)
|
|
27
|
+
activemodel (= 6.0.3.4)
|
|
28
|
+
activesupport (= 6.0.3.4)
|
|
29
|
+
activesupport (6.0.3.4)
|
|
25
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
31
|
i18n (>= 0.7, < 2)
|
|
27
32
|
minitest (~> 5.1)
|
|
28
33
|
tzinfo (~> 1.1)
|
|
29
|
-
zeitwerk (~> 2.
|
|
30
|
-
ast (2.4.
|
|
31
|
-
builder (3.2.
|
|
34
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
35
|
+
ast (2.4.1)
|
|
36
|
+
builder (3.2.4)
|
|
32
37
|
colorize (0.8.1)
|
|
33
|
-
concurrent-ruby (1.1.
|
|
34
|
-
crass (1.0.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
concurrent-ruby (1.1.7)
|
|
39
|
+
crass (1.0.6)
|
|
40
|
+
database_cleaner (1.8.5)
|
|
41
|
+
diff-lcs (1.4.4)
|
|
42
|
+
erubi (1.9.0)
|
|
43
|
+
fasterer (0.8.3)
|
|
38
44
|
colorize (~> 0.7)
|
|
39
|
-
ruby_parser (>= 3.
|
|
45
|
+
ruby_parser (>= 3.14.1)
|
|
40
46
|
generator_spec (0.9.4)
|
|
41
47
|
activesupport (>= 3.0.0)
|
|
42
48
|
railties (>= 3.0.0)
|
|
43
|
-
i18n (1.
|
|
49
|
+
i18n (1.8.5)
|
|
44
50
|
concurrent-ruby (~> 1.0)
|
|
45
|
-
jaro_winkler (1.5.3)
|
|
46
51
|
lite-errors (1.0.1)
|
|
47
52
|
lite-memoize (1.0.3)
|
|
48
|
-
loofah (2.
|
|
53
|
+
loofah (2.7.0)
|
|
49
54
|
crass (~> 1.0.2)
|
|
50
55
|
nokogiri (>= 1.5.9)
|
|
51
|
-
method_source (0.
|
|
56
|
+
method_source (1.0.0)
|
|
52
57
|
mini_portile2 (2.4.0)
|
|
53
|
-
minitest (5.
|
|
54
|
-
nokogiri (1.10.
|
|
58
|
+
minitest (5.14.2)
|
|
59
|
+
nokogiri (1.10.10)
|
|
55
60
|
mini_portile2 (~> 2.4.0)
|
|
56
|
-
parallel (1.
|
|
57
|
-
parser (2.
|
|
58
|
-
ast (~> 2.4.
|
|
59
|
-
rack (2.
|
|
61
|
+
parallel (1.19.2)
|
|
62
|
+
parser (2.7.2.0)
|
|
63
|
+
ast (~> 2.4.1)
|
|
64
|
+
rack (2.2.3)
|
|
60
65
|
rack-test (1.1.0)
|
|
61
66
|
rack (>= 1.0, < 3)
|
|
62
67
|
rails-dom-testing (2.0.3)
|
|
63
68
|
activesupport (>= 4.2.0)
|
|
64
69
|
nokogiri (>= 1.6)
|
|
65
|
-
rails-html-sanitizer (1.
|
|
66
|
-
loofah (~> 2.
|
|
67
|
-
railties (6.0.
|
|
68
|
-
actionpack (= 6.0.
|
|
69
|
-
activesupport (= 6.0.
|
|
70
|
+
rails-html-sanitizer (1.3.0)
|
|
71
|
+
loofah (~> 2.3)
|
|
72
|
+
railties (6.0.3.4)
|
|
73
|
+
actionpack (= 6.0.3.4)
|
|
74
|
+
activesupport (= 6.0.3.4)
|
|
70
75
|
method_source
|
|
71
76
|
rake (>= 0.8.7)
|
|
72
77
|
thor (>= 0.20.3, < 2.0)
|
|
73
78
|
rainbow (3.0.0)
|
|
74
|
-
rake (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
rspec-
|
|
79
|
-
|
|
80
|
-
rspec-
|
|
81
|
-
rspec-
|
|
79
|
+
rake (13.0.1)
|
|
80
|
+
regexp_parser (1.8.2)
|
|
81
|
+
rexml (3.2.4)
|
|
82
|
+
rspec (3.10.0)
|
|
83
|
+
rspec-core (~> 3.10.0)
|
|
84
|
+
rspec-expectations (~> 3.10.0)
|
|
85
|
+
rspec-mocks (~> 3.10.0)
|
|
86
|
+
rspec-core (3.10.0)
|
|
87
|
+
rspec-support (~> 3.10.0)
|
|
88
|
+
rspec-expectations (3.10.0)
|
|
82
89
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
-
rspec-support (~> 3.
|
|
84
|
-
rspec-mocks (3.
|
|
90
|
+
rspec-support (~> 3.10.0)
|
|
91
|
+
rspec-mocks (3.10.0)
|
|
85
92
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
86
|
-
rspec-support (~> 3.
|
|
87
|
-
rspec-support (3.
|
|
88
|
-
rubocop (
|
|
89
|
-
jaro_winkler (~> 1.5.1)
|
|
93
|
+
rspec-support (~> 3.10.0)
|
|
94
|
+
rspec-support (3.10.0)
|
|
95
|
+
rubocop (1.2.0)
|
|
90
96
|
parallel (~> 1.10)
|
|
91
|
-
parser (>= 2.
|
|
97
|
+
parser (>= 2.7.1.5)
|
|
92
98
|
rainbow (>= 2.2.2, < 4.0)
|
|
99
|
+
regexp_parser (>= 1.8)
|
|
100
|
+
rexml
|
|
101
|
+
rubocop-ast (>= 1.0.1)
|
|
93
102
|
ruby-progressbar (~> 1.7)
|
|
94
|
-
unicode-display_width (>= 1.4.0, <
|
|
95
|
-
rubocop-
|
|
96
|
-
|
|
97
|
-
rubocop-
|
|
98
|
-
rubocop (>= 0.
|
|
103
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
104
|
+
rubocop-ast (1.1.1)
|
|
105
|
+
parser (>= 2.7.1.5)
|
|
106
|
+
rubocop-performance (1.8.1)
|
|
107
|
+
rubocop (>= 0.87.0)
|
|
108
|
+
rubocop-ast (>= 0.4.0)
|
|
109
|
+
rubocop-rspec (2.0.0)
|
|
110
|
+
rubocop (~> 1.0)
|
|
111
|
+
rubocop-ast (>= 1.1.0)
|
|
99
112
|
ruby-progressbar (1.10.1)
|
|
100
|
-
ruby_parser (3.
|
|
113
|
+
ruby_parser (3.15.0)
|
|
101
114
|
sexp_processor (~> 4.9)
|
|
102
|
-
sexp_processor (4.
|
|
103
|
-
|
|
115
|
+
sexp_processor (4.15.1)
|
|
116
|
+
sqlite3 (1.4.2)
|
|
117
|
+
thor (1.0.1)
|
|
104
118
|
thread_safe (0.3.6)
|
|
105
|
-
tzinfo (1.2.
|
|
119
|
+
tzinfo (1.2.7)
|
|
106
120
|
thread_safe (~> 0.1)
|
|
107
|
-
unicode-display_width (1.
|
|
108
|
-
zeitwerk (2.1
|
|
121
|
+
unicode-display_width (1.7.0)
|
|
122
|
+
zeitwerk (2.4.1)
|
|
109
123
|
|
|
110
124
|
PLATFORMS
|
|
111
125
|
ruby
|
|
112
126
|
|
|
113
127
|
DEPENDENCIES
|
|
128
|
+
activerecord
|
|
114
129
|
bundler
|
|
130
|
+
database_cleaner
|
|
115
131
|
fasterer
|
|
116
132
|
generator_spec
|
|
117
133
|
lite-command!
|
|
@@ -120,6 +136,7 @@ DEPENDENCIES
|
|
|
120
136
|
rubocop
|
|
121
137
|
rubocop-performance
|
|
122
138
|
rubocop-rspec
|
|
139
|
+
sqlite3
|
|
123
140
|
|
|
124
141
|
BUNDLED WITH
|
|
125
|
-
2.
|
|
142
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -27,18 +27,21 @@ Or install it yourself as:
|
|
|
27
27
|
* [Setup](#setup)
|
|
28
28
|
* [Simple](#simple)
|
|
29
29
|
* [Complex](#complex)
|
|
30
|
+
* [Procedure](#procedure)
|
|
30
31
|
* [Extensions](#extensions)
|
|
31
32
|
|
|
32
33
|
## Setup
|
|
33
34
|
|
|
34
|
-
`rails g
|
|
35
|
-
`../app/commands/application_command.rb`
|
|
35
|
+
`rails g command NAME` will generate the following file:
|
|
36
36
|
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
end
|
|
37
|
+
```erb
|
|
38
|
+
app/commands/[NAME]_command.rb
|
|
40
39
|
```
|
|
41
40
|
|
|
41
|
+
If a `ApplicationCommand` file in the `app/commands` directory is available, the
|
|
42
|
+
generator will create file that inherit from `ApplicationCommand` if not it will
|
|
43
|
+
fallback to `Lite::Command::Complex`.
|
|
44
|
+
|
|
42
45
|
## Simple
|
|
43
46
|
|
|
44
47
|
Simple commands build quick class based calls but cannot be extended.
|
|
@@ -47,13 +50,9 @@ This is more of a traditional command service call as it only exposes a `call` m
|
|
|
47
50
|
```ruby
|
|
48
51
|
class SearchMovies < Lite::Command::Simple
|
|
49
52
|
|
|
50
|
-
class
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# NOTE: This class method is required
|
|
54
|
-
def execute(*args)
|
|
55
|
-
{ generate_fingerprint => movies_by_name }
|
|
56
|
-
end
|
|
53
|
+
# NOTE: This class method is required
|
|
54
|
+
def self.execute(*args)
|
|
55
|
+
{ generate_fingerprint => movies_by_name }
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
end
|
|
@@ -62,8 +61,7 @@ end
|
|
|
62
61
|
**Caller**
|
|
63
62
|
|
|
64
63
|
```ruby
|
|
65
|
-
|
|
66
|
-
command.call
|
|
64
|
+
SearchMovies.call('Toy Story')
|
|
67
65
|
```
|
|
68
66
|
|
|
69
67
|
## Complex
|
|
@@ -71,9 +69,6 @@ command.call
|
|
|
71
69
|
Complex commands can be used in instance and class based calls and
|
|
72
70
|
extended with access to errors and memoization.
|
|
73
71
|
|
|
74
|
-
Use `rails g decorator NAME` will generate the following file:
|
|
75
|
-
`../app/decorators/[name]_decorator.rb`
|
|
76
|
-
|
|
77
72
|
You will then need to fill this class with the required `execute` method as shown below:
|
|
78
73
|
|
|
79
74
|
```ruby
|
|
@@ -135,9 +130,39 @@ command.recall! #=> Clears the call, cache, errors, and then re-performs the cal
|
|
|
135
130
|
command.result #=> { 'fingerprint_2' => [ 'Toy Story 2', ... ] }
|
|
136
131
|
```
|
|
137
132
|
|
|
133
|
+
## Procedure
|
|
134
|
+
|
|
135
|
+
Procedures run a collection of commands. It uses the the complex procedure API
|
|
136
|
+
so it has access to all the methods. The `execute` method is already defined to
|
|
137
|
+
handle most common procedure steps. It can be use directly or subclassed.
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
class SearchChannels < Lite::Command::Procedure; end
|
|
141
|
+
|
|
142
|
+
procedure = SearchChannels.call(
|
|
143
|
+
DisneyChannel.new,
|
|
144
|
+
EspnChannel.new,
|
|
145
|
+
MtvChannel.new
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
procedure.result #=> ['disney: #3', 'espn: #59', 'mtv: #212']
|
|
149
|
+
procedure.steps #=> [<DisneyChannel @result="...">, <EspnChannel @result="...">, <MtvChannel @result="...">]
|
|
150
|
+
|
|
151
|
+
# If the errors extension is added you can stop the procedure at first failure.
|
|
152
|
+
procedure = SearchChannels.new(
|
|
153
|
+
DisneyChannel.new,
|
|
154
|
+
ErrorChannel.new,
|
|
155
|
+
MtvChannel.new
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
procedure.exit_on_failure = true
|
|
159
|
+
procedure.call
|
|
160
|
+
procedure.result #=> ['disney: #3']
|
|
161
|
+
```
|
|
162
|
+
|
|
138
163
|
## Extensions
|
|
139
164
|
|
|
140
|
-
Extend complex base command with any of the following extensions:
|
|
165
|
+
Extend complex (and procedures) base command with any of the following extensions:
|
|
141
166
|
|
|
142
167
|
### Errors (optional)
|
|
143
168
|
|
|
@@ -194,6 +219,28 @@ command.merge_errors!(command_2)
|
|
|
194
219
|
user_model.merge_errors!(command, direction: :to)
|
|
195
220
|
```
|
|
196
221
|
|
|
222
|
+
### Propagation (optional)
|
|
223
|
+
|
|
224
|
+
Propagation methods help you perform an action on an object. If successful is
|
|
225
|
+
returns the result else it adds the object errors to the form object. Available
|
|
226
|
+
propagation methods are:
|
|
227
|
+
`create_and_return!(object, params)`, `update_and_return!(object, params)`,
|
|
228
|
+
`save_and_return!(object)`, and `destroy_and_return!(object)`
|
|
229
|
+
|
|
230
|
+
```ruby
|
|
231
|
+
class SearchMovies < Lite::Command::Complex
|
|
232
|
+
include Lite::Command::Extensions::Errors
|
|
233
|
+
include Lite::Command::Extensions::Propagation
|
|
234
|
+
|
|
235
|
+
# ... ommited ...
|
|
236
|
+
|
|
237
|
+
def execute
|
|
238
|
+
create_and_return!(User, name: 'John Doe')
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
end
|
|
242
|
+
```
|
|
243
|
+
|
|
197
244
|
### Memoize (optional)
|
|
198
245
|
|
|
199
246
|
Learn more about using [Lite::Memoize](https://github.com/drexed/lite-memoize)
|
data/lib/generators/rails/USAGE
CHANGED
|
@@ -10,16 +10,9 @@ module Rails
|
|
|
10
10
|
|
|
11
11
|
def copy_files
|
|
12
12
|
path = File.join('app', 'commands', class_path, "#{file_name}_command.rb")
|
|
13
|
-
empty_directory('app/commands')
|
|
14
13
|
template('command.rb.tt', path)
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
def copy_specs
|
|
18
|
-
path = File.join('spec', 'commands', class_path, "#{file_name}_command_spec.rb")
|
|
19
|
-
empty_directory('spec/commands')
|
|
20
|
-
template('spec.rb.tt', path)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
16
|
private
|
|
24
17
|
|
|
25
18
|
def file_name
|
data/lib/lite/command.rb
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require 'lite/command/version'
|
|
4
4
|
|
|
5
|
-
%w[errors memoize].each do |name|
|
|
5
|
+
%w[errors memoize propagation].each do |name|
|
|
6
6
|
require "lite/command/extensions/#{name}"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
%w[exceptions states complex
|
|
9
|
+
%w[exceptions states simple complex procedure].each do |name|
|
|
10
10
|
require "lite/command/#{name}"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
require 'generators/lite/command/install_generator'
|
|
14
13
|
require 'generators/rails/command_generator'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lite
|
|
4
|
+
module Command
|
|
5
|
+
module Extensions
|
|
6
|
+
module Propagation
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
%i[archive destroy save].each do |action|
|
|
11
|
+
define_method("#{action}_and_return!") do |klass|
|
|
12
|
+
merge_errors!(klass) unless klass.send(action)
|
|
13
|
+
klass
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_and_return!(klass, params)
|
|
18
|
+
klass = klass.create(params)
|
|
19
|
+
merge_errors!(klass) unless klass.errors.empty?
|
|
20
|
+
klass
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def update_and_return!(klass, params)
|
|
24
|
+
merge_errors!(klass) unless klass.update(params)
|
|
25
|
+
klass
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lite
|
|
4
|
+
module Command
|
|
5
|
+
class Procedure < Complex
|
|
6
|
+
|
|
7
|
+
include Lite::Command::Extensions::Errors
|
|
8
|
+
|
|
9
|
+
attr_accessor :exit_on_failure
|
|
10
|
+
|
|
11
|
+
def execute
|
|
12
|
+
steps.each_with_object([]) do |command, results|
|
|
13
|
+
command.call
|
|
14
|
+
|
|
15
|
+
if respond_to?(:errors) && command.respond_to?(:errors) && command.failure?
|
|
16
|
+
merge_errors!(command)
|
|
17
|
+
break results if exit_on_failure?
|
|
18
|
+
else
|
|
19
|
+
results << command.result
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def exit_on_failure?
|
|
25
|
+
@exit_on_failure ||= false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def steps
|
|
29
|
+
@steps ||= @args.flatten
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/lite/command/version.rb
CHANGED
data/lite-command.gemspec
CHANGED
|
@@ -40,7 +40,9 @@ Gem::Specification.new do |spec|
|
|
|
40
40
|
spec.add_dependency 'lite-errors'
|
|
41
41
|
spec.add_dependency 'lite-memoize'
|
|
42
42
|
|
|
43
|
+
spec.add_development_dependency 'activerecord'
|
|
43
44
|
spec.add_development_dependency 'bundler'
|
|
45
|
+
spec.add_development_dependency 'database_cleaner'
|
|
44
46
|
spec.add_development_dependency 'fasterer'
|
|
45
47
|
spec.add_development_dependency 'generator_spec'
|
|
46
48
|
spec.add_development_dependency 'rake'
|
|
@@ -48,4 +50,5 @@ Gem::Specification.new do |spec|
|
|
|
48
50
|
spec.add_development_dependency 'rubocop'
|
|
49
51
|
spec.add_development_dependency 'rubocop-performance'
|
|
50
52
|
spec.add_development_dependency 'rubocop-rspec'
|
|
53
|
+
spec.add_development_dependency 'sqlite3'
|
|
51
54
|
end
|
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.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juan Gomez
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lite-errors
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activerecord
|
|
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
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: bundler
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +66,20 @@ dependencies:
|
|
|
52
66
|
- - ">="
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
68
|
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: database_cleaner
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
55
83
|
- !ruby/object:Gem::Dependency
|
|
56
84
|
name: fasterer
|
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -150,7 +178,21 @@ dependencies:
|
|
|
150
178
|
- - ">="
|
|
151
179
|
- !ruby/object:Gem::Version
|
|
152
180
|
version: '0'
|
|
153
|
-
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: sqlite3
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
195
|
+
description:
|
|
154
196
|
email:
|
|
155
197
|
- j.gomez@drexed.com
|
|
156
198
|
executables: []
|
|
@@ -173,17 +215,16 @@ files:
|
|
|
173
215
|
- _config.yml
|
|
174
216
|
- bin/console
|
|
175
217
|
- bin/setup
|
|
176
|
-
- lib/generators/lite/command/install_generator.rb
|
|
177
|
-
- lib/generators/lite/command/templates/install.rb
|
|
178
218
|
- lib/generators/rails/USAGE
|
|
179
219
|
- lib/generators/rails/command_generator.rb
|
|
180
220
|
- lib/generators/rails/templates/command.rb.tt
|
|
181
|
-
- lib/generators/rails/templates/spec.rb.tt
|
|
182
221
|
- lib/lite/command.rb
|
|
183
222
|
- lib/lite/command/complex.rb
|
|
184
223
|
- lib/lite/command/exceptions.rb
|
|
185
224
|
- lib/lite/command/extensions/errors.rb
|
|
186
225
|
- lib/lite/command/extensions/memoize.rb
|
|
226
|
+
- lib/lite/command/extensions/propagation.rb
|
|
227
|
+
- lib/lite/command/procedure.rb
|
|
187
228
|
- lib/lite/command/simple.rb
|
|
188
229
|
- lib/lite/command/states.rb
|
|
189
230
|
- lib/lite/command/version.rb
|
|
@@ -192,7 +233,7 @@ homepage: http://drexed.github.io/lite-command
|
|
|
192
233
|
licenses:
|
|
193
234
|
- MIT
|
|
194
235
|
metadata: {}
|
|
195
|
-
post_install_message:
|
|
236
|
+
post_install_message:
|
|
196
237
|
rdoc_options: []
|
|
197
238
|
require_paths:
|
|
198
239
|
- lib
|
|
@@ -207,8 +248,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
207
248
|
- !ruby/object:Gem::Version
|
|
208
249
|
version: '0'
|
|
209
250
|
requirements: []
|
|
210
|
-
rubygems_version: 3.
|
|
211
|
-
signing_key:
|
|
251
|
+
rubygems_version: 3.1.4
|
|
252
|
+
signing_key:
|
|
212
253
|
specification_version: 4
|
|
213
254
|
summary: Ruby Command based framework (aka service objects)
|
|
214
255
|
test_files: []
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails/generators'
|
|
4
|
-
|
|
5
|
-
module Lite
|
|
6
|
-
module Command
|
|
7
|
-
class InstallGenerator < Rails::Generators::Base
|
|
8
|
-
|
|
9
|
-
source_root File.expand_path('../templates', __FILE__)
|
|
10
|
-
|
|
11
|
-
def copy_application_query_file
|
|
12
|
-
copy_file('install.rb', 'app/commands/application_command.rb')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|