simple_command_dispatcher 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -4
- data/CHANGELOG.md +2 -0
- data/Gemfile +16 -7
- data/Gemfile.lock +13 -13
- 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: 417dc02ceb788cc887a1131e3a01f1c4e35d981e1a6adddcc9b127e015165277
|
4
|
+
data.tar.gz: 2281645d67460eb71041d3860e343a632f95d0fec0e4011a5928e50d8ae8ec6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b4dd400bb1d39a718f852e94a95d79ed595e82bdcd1e26ffc8991693a95d2d8e4e68a60031b78a41907dfb1c6c09bccf6c0c84b38909de0bd32ef89e972b34
|
7
|
+
data.tar.gz: 6a4dc18d0364dfd93ca75137729beae59b48655b9ddbbcf5d2bd5a79fa9469a00e239d23214ed17ffddfcef1a8fa52ae30b71e48776ae75527203afe28bb9500
|
data/.rubocop.yml
CHANGED
@@ -13,7 +13,8 @@ require:
|
|
13
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.
|
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.35', '< 2.0'
|
16
|
+
gem 'rubocop-performance', '>= 1.14', '< 2.0'
|
17
|
+
gem 'rubocop-rspec', '~> 2.25'
|
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,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_command_dispatcher (3.0.
|
4
|
+
simple_command_dispatcher (3.0.3)
|
5
5
|
activesupport (>= 7.0.8, < 8.0)
|
6
6
|
simple_command (~> 1.0, >= 1.0.1)
|
7
7
|
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
json (2.7.1)
|
35
35
|
language_server-protocol (3.17.0.3)
|
36
36
|
method_source (1.0.0)
|
37
|
-
minitest (5.
|
37
|
+
minitest (5.22.2)
|
38
38
|
mutex_m (0.2.0)
|
39
39
|
parallel (1.24.0)
|
40
40
|
parser (3.3.0.5)
|
@@ -55,19 +55,19 @@ GEM
|
|
55
55
|
psych (>= 4.0.0)
|
56
56
|
regexp_parser (2.9.0)
|
57
57
|
rexml (3.2.6)
|
58
|
-
rspec (3.
|
59
|
-
rspec-core (~> 3.
|
60
|
-
rspec-expectations (~> 3.
|
61
|
-
rspec-mocks (~> 3.
|
62
|
-
rspec-core (3.
|
63
|
-
rspec-support (~> 3.
|
64
|
-
rspec-expectations (3.
|
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.0)
|
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.0)
|
68
68
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-support (3.
|
69
|
+
rspec-support (~> 3.13.0)
|
70
|
+
rspec-support (3.13.0)
|
71
71
|
rubocop (1.60.2)
|
72
72
|
json (~> 2.3)
|
73
73
|
language_server-protocol (>= 3.17.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Ruby](https://github.com/gangelo/simple_command_dispatcher/actions/workflows/ruby.yml/badge.svg?refresh=2)](https://github.com/gangelo/simple_command_dispatcher/actions/workflows/ruby.yml)
|
2
|
-
[![GitHub version](https://badge.fury.io/gh/gangelo%2Fsimple_command_dispatcher.svg?refresh=
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/simple_command_dispatcher.svg?refresh=
|
2
|
+
[![GitHub version](https://badge.fury.io/gh/gangelo%2Fsimple_command_dispatcher.svg?refresh=4)](https://badge.fury.io/gh/gangelo%2Fsimple_command_dispatcher)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/simple_command_dispatcher.svg?refresh=4)](https://badge.fury.io/rb/simple_command_dispatcher)
|
4
4
|
[![](https://ruby-gem-downloads-badge.herokuapp.com/simple_command_dispatcher?type=total)](http://www.rubydoc.info/gems/simple_command_dispatcher/)
|
5
5
|
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/simple_command_dispatcher/)
|
6
6
|
[![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](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.3
|
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-02-
|
11
|
+
date: 2024-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|