simple_command_dispatcher 3.0.2 → 3.0.4
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/ruby.yml +2 -2
- data/.rubocop.yml +6 -8
- data/CHANGELOG.md +5 -0
- data/Gemfile +16 -7
- data/Gemfile.lock +50 -49
- data/README.md +35 -36
- data/Rakefile +6 -1
- data/lib/simple_command_dispatcher/klass_transform.rb +4 -1
- data/lib/simple_command_dispatcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: affdce217794089694d86418bdc80a5901dbe7621498e9498b044250e49c6d1c
|
4
|
+
data.tar.gz: 269ae817ca4bb2b199daba300bbce52f3aacce51d262d81f5a17171394218564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f229d94273cc3a072be9e9f1ed212c4fc50d0cc914e9ac425776912cdbdceaa706fcb80f26711317796fdade20fe6c6ad94a6bdcf39daebd4837d3825f24cef
|
7
|
+
data.tar.gz: ab780c6fb47d74dede8675fafd9cf381f41d6307f1800bc65996b9392a0a358a226f676975006db90a4f2094fcb82671308582918f2867e9e2dc4a943dd0c427
|
data/.github/workflows/ruby.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -9,11 +9,12 @@
|
|
9
9
|
#
|
10
10
|
# See https://docs.rubocop.org/rubocop/configuration
|
11
11
|
require:
|
12
|
-
- rubocop-performance
|
13
|
-
- rubocop-rspec
|
12
|
+
# - rubocop-performance
|
13
|
+
# - rubocop-rspec
|
14
14
|
|
15
15
|
AllCops:
|
16
|
-
|
16
|
+
SuggestExtensions: false
|
17
|
+
TargetRubyVersion: 3.0.1
|
17
18
|
NewCops: enable
|
18
19
|
Exclude:
|
19
20
|
- '.git/**/*'
|
@@ -127,9 +128,6 @@ Layout/LineLength:
|
|
127
128
|
# Avoid methods longer than 15 lines of code.
|
128
129
|
Metrics/MethodLength:
|
129
130
|
Max: 20
|
130
|
-
IgnoredMethods:
|
131
|
-
- swagger_path
|
132
|
-
- operation
|
133
131
|
|
134
132
|
|
135
133
|
# A complexity metric geared towards measuring complexity for a human reader.
|
@@ -141,8 +139,8 @@ Metrics/PerceivedComplexity:
|
|
141
139
|
# - 'lib/file.rb'
|
142
140
|
|
143
141
|
# Allow `downcase == ` instead of forcing `casecmp`
|
144
|
-
Performance/Casecmp:
|
145
|
-
Enabled: false
|
142
|
+
#Performance/Casecmp:
|
143
|
+
# Enabled: false
|
146
144
|
|
147
145
|
# Require children definitions to be nested or compact in classes and modules
|
148
146
|
Style/ClassAndModuleChildren:
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -7,11 +7,20 @@ gemspec
|
|
7
7
|
|
8
8
|
gem 'bundler', '~> 2.5', '>= 2.5.3'
|
9
9
|
gem 'colorize', '>= 0.8.1', '< 2.0'
|
10
|
-
gem 'pry-byebug', '>= 3.9', '< 4.0'
|
11
10
|
gem 'rake', '>= 13.0', '< 14.0'
|
12
|
-
|
13
|
-
|
14
|
-
gem '
|
15
|
-
gem '
|
16
|
-
gem 'rubocop
|
17
|
-
gem '
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem 'pry-byebug', '>= 3.9', '< 4.0'
|
14
|
+
gem 'rdoc', '>= 6.4', '< 7.0'
|
15
|
+
gem 'rubocop', '>= 1.62', '< 2.0'
|
16
|
+
gem 'rubocop-performance', '>= 1.20', '< 2.0'
|
17
|
+
gem 'rubocop-rspec', '>= 2.28', '< 3.0'
|
18
|
+
end
|
19
|
+
|
20
|
+
group :test do
|
21
|
+
gem 'rspec', '>= 3.10', '< 4.0'
|
22
|
+
end
|
23
|
+
|
24
|
+
group :documentation do
|
25
|
+
gem 'yard', '>= 0.9.28', '< 1.0'
|
26
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_command_dispatcher (3.0.
|
4
|
+
simple_command_dispatcher (3.0.4)
|
5
5
|
activesupport (>= 7.0.8, < 8.0)
|
6
6
|
simple_command (~> 1.0, >= 1.0.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.1.3)
|
11
|
+
activesupport (7.1.3.4)
|
12
12
|
base64
|
13
13
|
bigdecimal
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -20,24 +20,23 @@ GEM
|
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
ast (2.4.2)
|
22
22
|
base64 (0.2.0)
|
23
|
-
bigdecimal (3.1.
|
23
|
+
bigdecimal (3.1.8)
|
24
24
|
byebug (11.1.3)
|
25
25
|
coderay (1.1.3)
|
26
26
|
colorize (1.1.0)
|
27
|
-
concurrent-ruby (1.
|
27
|
+
concurrent-ruby (1.3.3)
|
28
28
|
connection_pool (2.4.1)
|
29
29
|
diff-lcs (1.5.1)
|
30
|
-
drb (2.2.
|
31
|
-
|
32
|
-
i18n (1.14.1)
|
30
|
+
drb (2.2.1)
|
31
|
+
i18n (1.14.5)
|
33
32
|
concurrent-ruby (~> 1.0)
|
34
|
-
json (2.7.
|
33
|
+
json (2.7.2)
|
35
34
|
language_server-protocol (3.17.0.3)
|
36
|
-
method_source (1.
|
37
|
-
minitest (5.
|
35
|
+
method_source (1.1.0)
|
36
|
+
minitest (5.24.1)
|
38
37
|
mutex_m (0.2.0)
|
39
|
-
parallel (1.
|
40
|
-
parser (3.3.0
|
38
|
+
parallel (1.25.1)
|
39
|
+
parser (3.3.4.0)
|
41
40
|
ast (~> 2.4.1)
|
42
41
|
racc
|
43
42
|
pry (0.14.2)
|
@@ -48,64 +47,66 @@ GEM
|
|
48
47
|
pry (>= 0.13, < 0.15)
|
49
48
|
psych (5.1.2)
|
50
49
|
stringio
|
51
|
-
racc (1.
|
50
|
+
racc (1.8.1)
|
52
51
|
rainbow (3.1.1)
|
53
|
-
rake (13.1
|
54
|
-
rdoc (6.
|
52
|
+
rake (13.2.1)
|
53
|
+
rdoc (6.7.0)
|
55
54
|
psych (>= 4.0.0)
|
56
|
-
regexp_parser (2.9.
|
57
|
-
rexml (3.
|
58
|
-
|
59
|
-
|
60
|
-
rspec-
|
61
|
-
rspec-
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
regexp_parser (2.9.2)
|
56
|
+
rexml (3.3.4)
|
57
|
+
strscan
|
58
|
+
rspec (3.13.0)
|
59
|
+
rspec-core (~> 3.13.0)
|
60
|
+
rspec-expectations (~> 3.13.0)
|
61
|
+
rspec-mocks (~> 3.13.0)
|
62
|
+
rspec-core (3.13.0)
|
63
|
+
rspec-support (~> 3.13.0)
|
64
|
+
rspec-expectations (3.13.1)
|
65
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
-
rspec-support (~> 3.
|
67
|
-
rspec-mocks (3.
|
66
|
+
rspec-support (~> 3.13.0)
|
67
|
+
rspec-mocks (3.13.1)
|
68
68
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-support (3.
|
71
|
-
rubocop (1.
|
69
|
+
rspec-support (~> 3.13.0)
|
70
|
+
rspec-support (3.13.1)
|
71
|
+
rubocop (1.65.1)
|
72
72
|
json (~> 2.3)
|
73
73
|
language_server-protocol (>= 3.17.0)
|
74
74
|
parallel (~> 1.10)
|
75
75
|
parser (>= 3.3.0.2)
|
76
76
|
rainbow (>= 2.2.2, < 4.0)
|
77
|
-
regexp_parser (>=
|
77
|
+
regexp_parser (>= 2.4, < 3.0)
|
78
78
|
rexml (>= 3.2.5, < 4.0)
|
79
|
-
rubocop-ast (>= 1.
|
79
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
80
80
|
ruby-progressbar (~> 1.7)
|
81
81
|
unicode-display_width (>= 2.4.0, < 3.0)
|
82
|
-
rubocop-ast (1.
|
83
|
-
parser (>= 3.
|
84
|
-
rubocop-capybara (2.
|
82
|
+
rubocop-ast (1.31.3)
|
83
|
+
parser (>= 3.3.1.0)
|
84
|
+
rubocop-capybara (2.21.0)
|
85
85
|
rubocop (~> 1.41)
|
86
|
-
rubocop-factory_bot (2.
|
87
|
-
rubocop (~> 1.
|
88
|
-
rubocop-performance (1.
|
86
|
+
rubocop-factory_bot (2.26.1)
|
87
|
+
rubocop (~> 1.61)
|
88
|
+
rubocop-performance (1.21.1)
|
89
89
|
rubocop (>= 1.48.1, < 2.0)
|
90
|
-
rubocop-ast (>= 1.
|
91
|
-
rubocop-rspec (2.
|
90
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
91
|
+
rubocop-rspec (2.31.0)
|
92
92
|
rubocop (~> 1.40)
|
93
93
|
rubocop-capybara (~> 2.17)
|
94
94
|
rubocop-factory_bot (~> 2.22)
|
95
|
+
rubocop-rspec_rails (~> 2.28)
|
96
|
+
rubocop-rspec_rails (2.29.1)
|
97
|
+
rubocop (~> 1.61)
|
95
98
|
ruby-progressbar (1.13.0)
|
96
|
-
ruby2_keywords (0.0.5)
|
97
99
|
simple_command (1.0.1)
|
98
|
-
stringio (3.1.
|
100
|
+
stringio (3.1.1)
|
101
|
+
strscan (3.1.0)
|
99
102
|
tzinfo (2.0.6)
|
100
103
|
concurrent-ruby (~> 1.0)
|
101
104
|
unicode-display_width (2.5.0)
|
102
|
-
yard (0.9.
|
105
|
+
yard (0.9.36)
|
103
106
|
|
104
107
|
PLATFORMS
|
105
|
-
|
106
|
-
x86_64-darwin-20
|
108
|
+
ruby
|
107
109
|
x86_64-darwin-21
|
108
|
-
x86_64-linux
|
109
110
|
|
110
111
|
DEPENDENCIES
|
111
112
|
bundler (~> 2.5, >= 2.5.3)
|
@@ -114,11 +115,11 @@ DEPENDENCIES
|
|
114
115
|
rake (>= 13.0, < 14.0)
|
115
116
|
rdoc (>= 6.4, < 7.0)
|
116
117
|
rspec (>= 3.10, < 4.0)
|
117
|
-
rubocop (>= 1.
|
118
|
-
rubocop-performance (>= 1.
|
119
|
-
rubocop-rspec (
|
118
|
+
rubocop (>= 1.62, < 2.0)
|
119
|
+
rubocop-performance (>= 1.20, < 2.0)
|
120
|
+
rubocop-rspec (>= 2.28, < 3.0)
|
120
121
|
simple_command_dispatcher!
|
121
122
|
yard (>= 0.9.28, < 1.0)
|
122
123
|
|
123
124
|
BUNDLED WITH
|
124
|
-
2.5.
|
125
|
+
2.5.6
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[](https://github.com/gangelo/simple_command_dispatcher/actions/workflows/ruby.yml)
|
2
|
-
[](https://badge.fury.io/gh/gangelo%2Fsimple_command_dispatcher)
|
3
|
+
[](https://badge.fury.io/rb/simple_command_dispatcher)
|
4
4
|
[](http://www.rubydoc.info/gems/simple_command_dispatcher/)
|
5
5
|
[](http://www.rubydoc.info/gems/simple_command_dispatcher/)
|
6
6
|
[](https://github.com/gangelo/simple_command_dispatcher/issues)
|
@@ -10,7 +10,7 @@
|
|
10
10
|
# A. It's a Ruby gem!!!
|
11
11
|
|
12
12
|
## Overview
|
13
|
-
__simple_command_dispatcher__ (SCD) allows you to execute __simple_command__ commands (and now _custom commands_ as of version 1.2.1) in a more dynamic way. If you are not familiar with the _simple_command_ gem, check it out [here][simple-command]. SCD was written specifically with the [rails-api][rails-api] in mind; however, you can use SDC wherever you would use simple_command commands.
|
13
|
+
__simple_command_dispatcher__ (SCD) allows you to execute __simple_command__ commands (and now _custom commands_ as of version 1.2.1) in a more dynamic way. If you are not familiar with the _simple_command_ gem, check it out [here][simple-command]. SCD was written specifically with the [rails-api][rails-api] in mind; however, you can use SDC wherever you would use simple_command commands.
|
14
14
|
|
15
15
|
## Update as of Version 1.2.1
|
16
16
|
### Custom Commands
|
@@ -29,31 +29,31 @@ This example assumes the following:
|
|
29
29
|
|
30
30
|
Command classes (and the modules they reside under) are named *__according to their file name and respective location within the above folder structure__*; for example, the command class defined in the `/api/my_app1/v1/authenticate_request.rb` file would be defined in this manner:
|
31
31
|
|
32
|
-
```ruby
|
32
|
+
```ruby
|
33
33
|
# /api/my_app1/v1/authenticate_request.rb
|
34
34
|
|
35
|
-
module Api
|
36
|
-
module MyApp1
|
37
|
-
module V1
|
38
|
-
class AuthenticateRequest
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
35
|
+
module Api
|
36
|
+
module MyApp1
|
37
|
+
module V1
|
38
|
+
class AuthenticateRequest
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
42
|
end
|
43
43
|
```
|
44
|
-
|
44
|
+
|
45
45
|
Likewise, the command class defined in the `/api/my_app2/v2/update_user.rb` file would be defined in this manner, and so on:
|
46
46
|
|
47
|
-
```ruby
|
47
|
+
```ruby
|
48
48
|
# /api/my_app2/v2/update_user.rb
|
49
49
|
|
50
|
-
module Api
|
51
|
-
module MyApp2
|
52
|
-
module V2
|
53
|
-
class UpdateUser
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
50
|
+
module Api
|
51
|
+
module MyApp2
|
52
|
+
module V2
|
53
|
+
class UpdateUser
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
57
|
end
|
58
58
|
```
|
59
59
|
|
@@ -81,8 +81,8 @@ The __routes used in this example__, conform to the following format: `"/api/[ap
|
|
81
81
|
#
|
82
82
|
# class Api::MyApp1::V1::AuthenticateRequest; end
|
83
83
|
#
|
84
|
-
# As opposed to this:
|
85
|
-
#
|
84
|
+
# As opposed to this:
|
85
|
+
#
|
86
86
|
# module Api
|
87
87
|
# module MyApp1
|
88
88
|
# module V1
|
@@ -138,10 +138,10 @@ end
|
|
138
138
|
# for custom command execution.
|
139
139
|
SimpleCommand::Dispatcher.configure do |config|
|
140
140
|
config.allow_custom_commands = true
|
141
|
-
end
|
141
|
+
end
|
142
142
|
```
|
143
143
|
|
144
|
-
```ruby
|
144
|
+
```ruby
|
145
145
|
# /app/controllers/application_controller.rb
|
146
146
|
|
147
147
|
require 'simple_command_dispatcher'
|
@@ -154,8 +154,8 @@ class ApplicationController < ActionController::API
|
|
154
154
|
|
155
155
|
def get_command_path
|
156
156
|
# request.env['PATH_INFO'] could return any number of paths. The important
|
157
|
-
# thing (in the case of our example), is that we get the portion of the
|
158
|
-
# path that uniquely identifies the SimpleCommand we need to call; this
|
157
|
+
# thing (in the case of our example), is that we get the portion of the
|
158
|
+
# path that uniquely identifies the SimpleCommand we need to call; this
|
159
159
|
# would include the application, the API version and the SimpleCommand
|
160
160
|
# name itself.
|
161
161
|
command_path = request.env['PATH_INFO'] # => "/api/[app name]/v1/[action]”
|
@@ -163,16 +163,16 @@ class ApplicationController < ActionController::API
|
|
163
163
|
end
|
164
164
|
|
165
165
|
private
|
166
|
-
|
166
|
+
|
167
167
|
def authenticate_request
|
168
168
|
# The parameters and options we are passing to the dispatcher, wind up equating
|
169
169
|
# to the following: Api::MyApp1::V1::AuthenticateRequest.call(request.headers).
|
170
|
-
# Explaination: @param command_modules (e.g. path, "/api/my_app1/v1/"), in concert with @param
|
171
|
-
# options { camelize: true }, is transformed into "Api::MyApp1::V1" and prepended to the
|
170
|
+
# Explaination: @param command_modules (e.g. path, "/api/my_app1/v1/"), in concert with @param
|
171
|
+
# options { camelize: true }, is transformed into "Api::MyApp1::V1" and prepended to the
|
172
172
|
# @param command, which becomes "Api::MyApp1::V1::AuthenticateRequest." This string is then
|
173
173
|
# simply constantized; #call is then executed, passing the @param command_parameters
|
174
174
|
# (e.g. request.headers, which contains ["Authorization"], out authorization token).
|
175
|
-
# Consequently, the correlation between our routes and command class module structure
|
175
|
+
# Consequently, the correlation between our routes and command class module structure
|
176
176
|
# was no coincidence.
|
177
177
|
command = SimpleCommand::Dispatcher.call(:AuthenticateRequest, get_command_path, { camelize: true}, request.headers)
|
178
178
|
if command.success?
|
@@ -191,7 +191,7 @@ As of __Version 1.2.1__ simple_command_dispatcher (SCD) allows you to execute _c
|
|
191
191
|
In order to execute _custom commands_, there are three (3) requirements:
|
192
192
|
1. Create a _custom command_. Your _custom command_ class must expose a public `::call` class method.
|
193
193
|
2. Set the `Configuration#allow_custom_commands` property to `true`.
|
194
|
-
3. Execute your _custom command_ by calling the `::call` class method.
|
194
|
+
3. Execute your _custom command_ by calling the `::call` class method.
|
195
195
|
|
196
196
|
### Custom Command Example
|
197
197
|
|
@@ -205,7 +205,7 @@ module Api
|
|
205
205
|
|
206
206
|
# This is a custom command that does not prepend SimpleCommand.
|
207
207
|
class CustomCommand
|
208
|
-
|
208
|
+
|
209
209
|
def self.call(*args)
|
210
210
|
command = self.new(*args)
|
211
211
|
if command
|
@@ -214,7 +214,7 @@ module Api
|
|
214
214
|
false
|
215
215
|
end
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
private
|
219
219
|
|
220
220
|
def initialize(params = {})
|
@@ -245,7 +245,7 @@ end
|
|
245
245
|
|
246
246
|
SimpleCommand::Dispatcher.configure do |config|
|
247
247
|
config.allow_custom_commands = true
|
248
|
-
end
|
248
|
+
end
|
249
249
|
```
|
250
250
|
|
251
251
|
#### 3. Execute your _Custom Command_
|
@@ -257,7 +257,7 @@ require 'simple_command_dispatcher'
|
|
257
257
|
|
258
258
|
class SomeController < ApplicationController::API
|
259
259
|
public
|
260
|
-
|
260
|
+
|
261
261
|
def some_api
|
262
262
|
success = SimpleCommand::Dispatcher.call(:CustomCommand, get_command_path, { camelize: true}, request.headers)
|
263
263
|
if success
|
@@ -306,4 +306,3 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
306
306
|
|
307
307
|
[simple-command]: <https://rubygems.org/gems/simple_command>
|
308
308
|
[rails-api]: <https://rubygems.org/gems/rails-api>
|
309
|
-
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'yard'
|
|
6
6
|
|
7
7
|
# Rspec
|
8
8
|
RSpec::Core::RakeTask.new(:spec)
|
9
|
-
task default: :spec
|
9
|
+
#task default: :spec
|
10
10
|
|
11
11
|
# Yard
|
12
12
|
YARD::Rake::YardocTask.new do |t|
|
@@ -17,3 +17,8 @@ end
|
|
17
17
|
|
18
18
|
# Load our custom rake tasks.
|
19
19
|
Gem.find_files('tasks/**/*.rake').each { |path| import path }
|
20
|
+
|
21
|
+
require 'rubocop/rake_task'
|
22
|
+
RuboCop::RakeTask.new
|
23
|
+
|
24
|
+
task default: %i[spec rubocop]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Style/OptionHash
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require_relative '../core_extensions/string'
|
@@ -94,7 +95,7 @@ module SimpleCommand
|
|
94
95
|
# to_modules_string({ :api :api, app_name: :app_name, api_version: :v1 }, { module_titleize: true })
|
95
96
|
# # => "Api::AppName::V1::"
|
96
97
|
#
|
97
|
-
def to_modules_string(klass_modules = [], options = {})
|
98
|
+
def to_modules_string(klass_modules = [], options = {}) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
98
99
|
klass_modules = validate_klass_modules(klass_modules)
|
99
100
|
|
100
101
|
options = ensure_options(options)
|
@@ -246,3 +247,5 @@ module SimpleCommand
|
|
246
247
|
end
|
247
248
|
end
|
248
249
|
end
|
250
|
+
|
251
|
+
# rubocop:enable Style/OptionHash
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_command_dispatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|