simple_command_dispatcher 3.0.4 → 4.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/.github/workflows/ruby.yml +47 -25
- data/.gitignore +3 -0
- data/.rubocop.yml +36 -41
- data/.ruby-version +1 -1
- data/CHANGELOG.md +173 -59
- data/Gemfile +3 -6
- data/Gemfile.lock +77 -70
- data/Jenkinsfile +2 -2
- data/README.md +312 -224
- data/Rakefile +0 -8
- data/lib/core_ext/kernel.rb +22 -0
- data/lib/simple_command_dispatcher/commands/command_callable.rb +52 -0
- data/lib/simple_command_dispatcher/commands/errors.rb +44 -0
- data/lib/simple_command_dispatcher/commands/utils.rb +20 -0
- data/lib/simple_command_dispatcher/configuration.rb +37 -35
- data/lib/simple_command_dispatcher/errors/invalid_class_constant_error.rb +16 -0
- data/lib/simple_command_dispatcher/errors/required_class_method_missing_error.rb +15 -0
- data/lib/simple_command_dispatcher/errors.rb +4 -0
- data/lib/simple_command_dispatcher/helpers/camelize.rb +46 -0
- data/lib/simple_command_dispatcher/helpers/trim_all.rb +16 -0
- data/lib/simple_command_dispatcher/services/command_namespace_service.rb +60 -0
- data/lib/simple_command_dispatcher/services/command_service.rb +152 -0
- data/lib/simple_command_dispatcher/version.rb +2 -4
- data/lib/simple_command_dispatcher.rb +70 -121
- data/simple_command_dispatcher.gemspec +9 -10
- metadata +26 -42
- data/lib/core_extensions/string.rb +0 -10
- data/lib/simple_command_dispatcher/configure.rb +0 -22
- data/lib/simple_command_dispatcher/klass_transform.rb +0 -251
- data/lib/tasks/simple_command_dispatcher_sandbox.rake +0 -222
@@ -1,222 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake'
|
4
|
-
# Tasks to play with certain klass_transform module members
|
5
|
-
|
6
|
-
desc 'Test to_class_string'
|
7
|
-
task :to_class_string do
|
8
|
-
require 'colorize'
|
9
|
-
require 'simple_command_dispatcher'
|
10
|
-
|
11
|
-
class Test
|
12
|
-
prepend SimpleCommand::KlassTransform
|
13
|
-
end
|
14
|
-
|
15
|
-
puts "Testing SimpleCommand::KlassTransform#to_class_String...\n".cyan
|
16
|
-
puts 'Enter a blank line to exit.'.cyan
|
17
|
-
loop do
|
18
|
-
puts "\nUsage: \"-c [class], -o [options]\" where class = String or Symbol and options = Hash".cyan
|
19
|
-
puts "\n\t Examples:"
|
20
|
-
print "\n\t\t-c \"my_class\" -o { class_camelize: true }".cyan
|
21
|
-
print "\n\t\t-c :MyClass -o { class_camelize: false }".cyan
|
22
|
-
|
23
|
-
print "\n=> "
|
24
|
-
|
25
|
-
input = $stdin.gets.chomp
|
26
|
-
break if input.empty?
|
27
|
-
|
28
|
-
input = clean_input(input)
|
29
|
-
|
30
|
-
klass = get_option_class(input)
|
31
|
-
if klass.nil? || klass.empty?
|
32
|
-
print "=> Error: Class not a String or Symbol\n".red
|
33
|
-
next
|
34
|
-
elsif !klass.is_a?(String) && !klass.is_a?(Symbol)
|
35
|
-
print "=> Error: Class not a String or Symbol\n".red
|
36
|
-
next
|
37
|
-
end
|
38
|
-
|
39
|
-
options_hash = get_options_hash(input)
|
40
|
-
|
41
|
-
options_hash = { class_camelize: true }.merge(options_hash || {})
|
42
|
-
|
43
|
-
puts "\nCalling to_class_string with the following parameters: class: #{klass.class}, options: #{options_hash.class}".cyan
|
44
|
-
|
45
|
-
print "\nSuccess: => #to_class_String(#{klass}, #{options_hash}) => #{Test.new.to_class_string(klass,
|
46
|
-
options_hash)}\n".green
|
47
|
-
end
|
48
|
-
|
49
|
-
print
|
50
|
-
print 'Done'.yellow
|
51
|
-
print
|
52
|
-
end
|
53
|
-
|
54
|
-
desc 'Test to_modules_string'
|
55
|
-
task :to_modules_string do
|
56
|
-
require 'colorize'
|
57
|
-
require 'simple_command_dispatcher'
|
58
|
-
|
59
|
-
class Test
|
60
|
-
prepend SimpleCommand::KlassTransform
|
61
|
-
end
|
62
|
-
|
63
|
-
puts "Testing SimpleCommand::KlassTransform#to_modules_string...\n".cyan
|
64
|
-
puts 'Enter a blank line to exit.'.cyan
|
65
|
-
loop do
|
66
|
-
puts "\nUsage: \"-m [modules], -o [options]\" where modules = Hash, Array or String and options = Hash".cyan
|
67
|
-
puts "\n\t Examples:"
|
68
|
-
print "\n\t\t-m \"Module1::Module2::Module3\" -o { modules_camelize: false }".cyan
|
69
|
-
print "\n\t\t-m [:module1, :module2, :module3] -o { modules_camelize: true }".cyan
|
70
|
-
print "\n\t\t-m {api: :api, app: :crazy_buttons, version: :v1} -o { modules_camelize: true }".cyan
|
71
|
-
|
72
|
-
print "\n=> "
|
73
|
-
|
74
|
-
input = $stdin.gets.chomp
|
75
|
-
break if input.empty?
|
76
|
-
|
77
|
-
input = clean_input(input)
|
78
|
-
|
79
|
-
modules = get_option_modules(input)
|
80
|
-
p modules.class
|
81
|
-
if modules.nil? || modules.empty?
|
82
|
-
print "=> Error: Modules not a Hash, Array or String\n".red
|
83
|
-
next
|
84
|
-
elsif !modules.is_a?(Hash) && !modules.is_a?(Array) && !modules.is_a?(String)
|
85
|
-
print "=> Error: Modules not a Hash, Array or String\n".red
|
86
|
-
next
|
87
|
-
end
|
88
|
-
|
89
|
-
options_hash = get_options_hash(input)
|
90
|
-
options_hash = { module_camelize: true }.merge(options_hash || {})
|
91
|
-
|
92
|
-
puts "\nCalling to_modules_string with the following parameters: modules: #{modules}, type: #{modules.class}, options: #{options_hash}, type: #{options_hash.class}...".cyan
|
93
|
-
|
94
|
-
puts "\nSuccess: => #to_modules_string(#{modules}, #{options_hash}) => #{Test.new.to_modules_string(modules,
|
95
|
-
options_hash)}\n".green
|
96
|
-
end
|
97
|
-
|
98
|
-
print
|
99
|
-
print 'Done'.yellow
|
100
|
-
print
|
101
|
-
end
|
102
|
-
|
103
|
-
desc 'Test to_constantized_class_string'
|
104
|
-
task :to_constantized_class_string do
|
105
|
-
require 'colorize'
|
106
|
-
require 'simple_command_dispatcher'
|
107
|
-
|
108
|
-
class Test
|
109
|
-
prepend SimpleCommand::KlassTransform
|
110
|
-
end
|
111
|
-
|
112
|
-
puts "Testing SimpleCommand::KlassTransform#to_constantized_class_string...\n".cyan
|
113
|
-
puts 'Enter a blank line to exit.'.cyan
|
114
|
-
loop do
|
115
|
-
puts "\nUsage: \"-c [class] -m [modules], -o [options]\" where class = Symbol or String, modules = Hash, Array or String and options = Hash".cyan
|
116
|
-
puts "\n\t Examples:"
|
117
|
-
print "\n\t\t-c :MyClass -m \"Module1::Module2::Module3\" -o { modules_camelize: false }".cyan
|
118
|
-
print "\n\t\t-c \"my_class\" -m [:module1, :module2, :module3] -o { modules_camelize: true }".cyan
|
119
|
-
print "\n\t\t-c :myClass -m {api: :api, app: :crazy_buttons, version: :v1} -o { modules_camelize: true }".cyan
|
120
|
-
|
121
|
-
print "\n=> "
|
122
|
-
|
123
|
-
input = $stdin.gets.chomp
|
124
|
-
break if input.empty?
|
125
|
-
|
126
|
-
input = clean_input(input)
|
127
|
-
|
128
|
-
klass = get_option_class(input)
|
129
|
-
if klass.nil? || klass.empty?
|
130
|
-
print "=> Error: Class not a String or Symbol\n".red
|
131
|
-
next
|
132
|
-
elsif !klass.is_a?(String) && !klass.is_a?(Symbol)
|
133
|
-
print "=> Error: Class not a String or Symbol\n".red
|
134
|
-
next
|
135
|
-
end
|
136
|
-
|
137
|
-
modules = get_option_modules(input)
|
138
|
-
if modules.nil? || modules.empty?
|
139
|
-
print "=> Error: Modules not a Hash, Array or String\n".red
|
140
|
-
next
|
141
|
-
elsif !modules.is_a?(Hash) && !modules.is_a?(Array) && !modules.is_a?(String)
|
142
|
-
print "=> Error: Modules not a Hash, Array or String\n".red
|
143
|
-
next
|
144
|
-
end
|
145
|
-
|
146
|
-
options_hash = get_options_hash(input)
|
147
|
-
options_hash = { class_camelize: true, module_camelize: true }.merge(options_hash || {})
|
148
|
-
|
149
|
-
puts "\nCalling to_constantized_class_string with the following parameters: class: #{klass}, type: #{klass.class}, modules: #{modules}, type: #{modules.class}, options: #{options_hash}, type: #{options_hash.class}...".cyan
|
150
|
-
|
151
|
-
puts "\nSuccess: => #to_constantized_class_string(#{klass}, #{modules}, #{options_hash}) => #{Test.new.to_constantized_class_string(
|
152
|
-
klass, modules, options_hash
|
153
|
-
)}\n".green
|
154
|
-
end
|
155
|
-
|
156
|
-
print
|
157
|
-
print 'Done'.yellow
|
158
|
-
print
|
159
|
-
end
|
160
|
-
|
161
|
-
#
|
162
|
-
# Helper methods
|
163
|
-
#
|
164
|
-
|
165
|
-
def clean_input(input)
|
166
|
-
# Place a space before every dash that is not separated by a space.
|
167
|
-
input = input.gsub(/-c/, ' -c ').gsub(/-m/, ' -m ').gsub(/-o/, ' -o ')
|
168
|
-
input = input.gsub(/"/, ' " ').gsub(/\s+/, ' ').strip
|
169
|
-
|
170
|
-
puts "=> keyboard input after clean_input => #{input}".magenta
|
171
|
-
|
172
|
-
input
|
173
|
-
end
|
174
|
-
|
175
|
-
def get_option_class(options)
|
176
|
-
return '' if options.nil? || options.empty?
|
177
|
-
|
178
|
-
options_options = options[/-c\s*([:"].+?(["\s-]||$?))($|\s+|-)/m, 1]
|
179
|
-
|
180
|
-
return '' if options_options.nil?
|
181
|
-
|
182
|
-
options_options = options_options.gsub(/("|')+/, '')
|
183
|
-
klass = options_options.strip.gsub(/\s+/, ' ')
|
184
|
-
|
185
|
-
puts "=> class after get_option_class => #{klass}".magenta
|
186
|
-
|
187
|
-
klass
|
188
|
-
end
|
189
|
-
|
190
|
-
def get_options_hash(options)
|
191
|
-
return {} if options.nil? || options.empty?
|
192
|
-
|
193
|
-
options_options = options[/-o\s*([{].+?([}\s-]$?))($|\s+|-)/m, 1]
|
194
|
-
|
195
|
-
return {} if options_options.nil?
|
196
|
-
|
197
|
-
puts "=> options after get_options_hash => #{options_options}".magenta
|
198
|
-
|
199
|
-
begin
|
200
|
-
eval(options_options)
|
201
|
-
rescue StandardError
|
202
|
-
{}
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def get_option_modules(modules)
|
207
|
-
return '' if modules.nil? || modules.empty?
|
208
|
-
|
209
|
-
extracted_modules = modules[/-m\s*([\[{"].+?(["}\]\s-]$?))($|\s+|-)/m, 1]
|
210
|
-
|
211
|
-
return '' if extracted_modules.nil?
|
212
|
-
|
213
|
-
extracted_modules = extracted_modules.strip.gsub(/\s+/, ' ')
|
214
|
-
|
215
|
-
puts "=> modules after get_option_modules => #{extracted_modules}".magenta
|
216
|
-
|
217
|
-
begin
|
218
|
-
eval(extracted_modules)
|
219
|
-
rescue StandardError
|
220
|
-
''
|
221
|
-
end
|
222
|
-
end
|