simple_command_dispatcher 1.2.2 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
- require "simple_command_dispatcher/version"
2
- require "simple_command_dispatcher/klass_transform"
3
- require "simple_command"
4
- require "active_support/core_ext/string/inflections"
1
+ # frozen_string_literal: true
5
2
 
6
- require 'simple_command_dispatcher/configuration'
3
+ require 'simple_command_dispatcher/version'
4
+ require 'simple_command_dispatcher/klass_transform'
5
+ require 'simple_command'
6
+ require 'active_support/core_ext/string/inflections'
7
7
  require 'simple_command_dispatcher/configure'
8
8
 
9
9
  module Kernel
@@ -15,116 +15,107 @@ module Kernel
15
15
  end
16
16
 
17
17
  module SimpleCommand
18
-
19
- # Provides a way to call SimpleCommands or your own custom commands in a more dymanic manner.
20
- #
21
- # For information about the simple_command gem, visit {https://rubygems.org/gems/simple_command}
22
- #
23
- module Dispatcher
24
-
25
- class << self
26
- include SimpleCommand::KlassTransform
27
-
28
- public
29
-
30
- # Calls a *SimpleCommand* or *Command* given the command name, the modules the command belongs to and the parameters to pass to the command.
31
- #
32
- # @param command [Symbol, String] the name of the SimpleCommand or Command to call.
33
- #
34
- # @param command_modules [Hash, Array] the ruby modules that qualify the SimpleCommand to call. When passing a Hash, the Hash
35
- # keys serve as documentation only. For example, ['Api', 'AppName', 'V1'] and { :api :Api, app_name: :AppName, api_version: :V1 }
36
- # will both produce 'Api::AppName::V1', this string will be prepended to the command to form the SimpleCommand to call
37
- # (e.g. 'Api::AppName::V1::MySimpleCommand' = Api::AppName::V1::MySimpleCommand.call(*command_parameters)).
38
- #
39
- # @param [Hash] options the options that determine how command and command_module are transformed.
40
- # @option options [Boolean] :camelize (false) determines whether or not both class and module names should be camelized.
41
- # @option options [Boolean] :titleize (false) determines whether or not both class and module names should be titleized.
42
- # @option options [Boolean] :class_titleize (false) determines whether or not class names should be titleized.
43
- # @option options [Boolean] :class_camelized (false) determines whether or not class names should be camelized.
44
- # @option options [Boolean] :module_titleize (false) determines whether or not module names should be titleized.
45
- # @option options [Boolean] :module_camelized (false) determines whether or not module names should be camelized.
46
- #
47
- # @param command_parameters [Array<Symbol>] the parameters to pass to the call method of the SimpleCommand . This parameter is simply
48
- # passed through to the call method of the SimpleCommand/Command.
49
- #
50
- # @return [SimpleCommand, Object] the SimpleCommand or Object returned as a result of calling the SimpleCommand#call method or the Command#call method respectfully.
51
- #
52
- # @example
53
- #
54
- # # Below call equates to the following: Api::Carz4Rent::V1::Authenticate.call({ email: 'sam@gmail.com', password: 'AskM3!' })
55
- # SimpleCommand::Dispatcher.call(:Authenticate, { api: :Api, app_name: :Carz4Rent, api_version: :V1 },
56
- # { email: 'sam@gmail.com', password: 'AskM3!' } ) # => SimpleCommand result
57
- #
58
- # # Below equates to the following: Api::Carz4Rent::V2::Authenticate.call('sam@gmail.com', 'AskM3!')
59
- # SimpleCommand::Dispatcher.call(:Authenticate, ['Api', 'Carz4Rent', 'V2'], 'sam@gmail.com', 'AskM3!') # => SimpleCommand result
60
- #
61
- # # Below equates to the following: Api::Auth::JazzMeUp::V1::Authenticate.call('jazz_me@gmail.com', 'JazzM3!')
62
- # SimpleCommand::Dispatcher.call(:Authenticate, ['Api::Auth::JazzMeUp', :V1], 'jazz_me@gmail.com', 'JazzM3!') # => SimpleCommand result
63
- #
64
- def call(command = "", command_modules = {}, options = {}, *command_parameters)
18
+ # Provides a way to call SimpleCommands or your own custom commands in a more dymanic manner.
19
+ #
20
+ # For information about the simple_command gem, visit {https://rubygems.org/gems/simple_command}
21
+ #
22
+ module Dispatcher
23
+ class << self
24
+ include SimpleCommand::KlassTransform
65
25
 
66
- # Create a constantized class from our command and command_modules...
67
- command_class_constant = to_constantized_class(command, command_modules, options)
26
+ # Calls a *SimpleCommand* or *Command* given the command name, the modules the command belongs to and the parameters to pass to the command.
27
+ #
28
+ # @param command [Symbol, String] the name of the SimpleCommand or Command to call.
29
+ #
30
+ # @param command_modules [Hash, Array] the ruby modules that qualify the SimpleCommand to call. When passing a Hash, the Hash
31
+ # keys serve as documentation only. For example, ['Api', 'AppName', 'V1'] and { :api :Api, app_name: :AppName, api_version: :V1 }
32
+ # will both produce 'Api::AppName::V1', this string will be prepended to the command to form the SimpleCommand to call
33
+ # (e.g. 'Api::AppName::V1::MySimpleCommand' = Api::AppName::V1::MySimpleCommand.call(*command_parameters)).
34
+ #
35
+ # @param [Hash] options the options that determine how command and command_module are transformed.
36
+ # @option options [Boolean] :camelize (false) determines whether or not both class and module names should be camelized.
37
+ # @option options [Boolean] :titleize (false) determines whether or not both class and module names should be titleized.
38
+ # @option options [Boolean] :class_titleize (false) determines whether or not class names should be titleized.
39
+ # @option options [Boolean] :class_camelized (false) determines whether or not class names should be camelized.
40
+ # @option options [Boolean] :module_titleize (false) determines whether or not module names should be titleized.
41
+ # @option options [Boolean] :module_camelized (false) determines whether or not module names should be camelized.
42
+ #
43
+ # @param command_parameters [Array<Symbol>] the parameters to pass to the call method of the SimpleCommand . This parameter is simply
44
+ # passed through to the call method of the SimpleCommand/Command.
45
+ #
46
+ # @return [SimpleCommand, Object] the SimpleCommand or Object returned as a result of calling the SimpleCommand#call method or the Command#call method respectfully.
47
+ #
48
+ # @example
49
+ #
50
+ # # Below call equates to the following: Api::Carz4Rent::V1::Authenticate.call({ email: 'sam@gmail.com', password: 'AskM3!' })
51
+ # SimpleCommand::Dispatcher.call(:Authenticate, { api: :Api, app_name: :Carz4Rent, api_version: :V1 },
52
+ # { email: 'sam@gmail.com', password: 'AskM3!' } ) # => SimpleCommand result
53
+ #
54
+ # # Below equates to the following: Api::Carz4Rent::V2::Authenticate.call('sam@gmail.com', 'AskM3!')
55
+ # SimpleCommand::Dispatcher.call(:Authenticate, ['Api', 'Carz4Rent', 'V2'], 'sam@gmail.com', 'AskM3!') # => SimpleCommand result
56
+ #
57
+ # # Below equates to the following: Api::Auth::JazzMeUp::V1::Authenticate.call('jazz_me@gmail.com', 'JazzM3!')
58
+ # SimpleCommand::Dispatcher.call(:Authenticate, ['Api::Auth::JazzMeUp', :V1], 'jazz_me@gmail.com', 'JazzM3!') # => SimpleCommand result
59
+ #
60
+ def call(command = '', command_modules = {}, options = {}, *command_parameters)
61
+ # Create a constantized class from our command and command_modules...
62
+ command_class_constant = to_constantized_class(command, command_modules, options)
68
63
 
69
- # If we're NOT allowing custom commands, make sure we're dealing with a a command class
70
- # that prepends the SimpleCommand module.
71
- if !SimpleCommand::Dispatcher.configuration.allow_custom_commands
72
- # Calling is_simple_command? returns true if the class pointed to by
73
- # command_class_constant is a valid SimpleCommand class; that is,
74
- # if it prepends module SimpleCommand::ClassMethods.
75
- if !is_simple_command?(command_class_constant)
76
- raise ArgumentError.new("Class \"#{command_class_constant}\" must prepend module SimpleCommand if Configuration#allow_custom_commands is true.")
77
- end
78
- end
64
+ # If we're NOT allowing custom commands, make sure we're dealing with a a command class
65
+ # that prepends the SimpleCommand module.
66
+ if !SimpleCommand::Dispatcher.configuration.allow_custom_commands && !is_simple_command?(command_class_constant)
67
+ raise ArgumentError,
68
+ "Class \"#{command_class_constant}\" must prepend module SimpleCommand if Configuration#allow_custom_commands is true."
69
+ end
79
70
 
80
- if is_valid_command(command_class_constant)
81
- # We know we have a valid SimpleCommand; all we need to do is call #call,
82
- # pass the command_parameter variable arguments to the call, and return the results.
83
- run_command(command_class_constant, command_parameters)
84
- else
85
- raise NameError.new("Class \"#{command_class_constant}\" does not respond_to? method ::call.")
86
- end
87
- end
71
+ if is_valid_command(command_class_constant)
72
+ # We know we have a valid SimpleCommand; all we need to do is call #call,
73
+ # pass the command_parameter variable arguments to the call, and return the results.
74
+ run_command(command_class_constant, command_parameters)
75
+ else
76
+ raise NameError, "Class \"#{command_class_constant}\" does not respond_to? method ::call."
77
+ end
78
+ end
88
79
 
89
- private
80
+ private
90
81
 
91
- # Returns true or false depending on whether or not the class constant has a public
92
- # class method named ::call defined. Commands that do not have a public class method
93
- # named ::call, are considered invalid.
94
- #
95
- # @param klass_constant [String] a class constant that will be validated to see whether or not the class is a valid command.
96
- #
97
- # @return [Boolean] true if klass_constant has a public class method named ::call defined, false otherwise.
98
- #
99
- # @!visibility public
100
- def is_valid_command(klass_constant)
101
- klass_constant.eigenclass.public_method_defined?(:call)
102
- end
82
+ # Returns true or false depending on whether or not the class constant has a public
83
+ # class method named ::call defined. Commands that do not have a public class method
84
+ # named ::call, are considered invalid.
85
+ #
86
+ # @param klass_constant [String] a class constant that will be validated to see whether or not the class is a valid command.
87
+ #
88
+ # @return [Boolean] true if klass_constant has a public class method named ::call defined, false otherwise.
89
+ #
90
+ # @!visibility public
91
+ def is_valid_command(klass_constant)
92
+ klass_constant.eigenclass.public_method_defined?(:call)
93
+ end
103
94
 
104
- # Returns true or false depending on whether or not the class constant prepends module SimpleCommand::ClassMethods.
105
- #
106
- # @param klass_constant [String] a class constant that will be validated to see whether or not the class prepends module SimpleCommand::ClassMethods.
107
- #
108
- # @return [Boolean] true if klass_constant prepends Module SimpleCommand::ClassMethods, false otherwise.
109
- #
110
- # @!visibility public
111
- def is_simple_command?(klass_constant)
112
- klass_constant.eigenclass.included_modules.include? SimpleCommand::ClassMethods
113
- end
95
+ # Returns true or false depending on whether or not the class constant prepends module SimpleCommand::ClassMethods.
96
+ #
97
+ # @param klass_constant [String] a class constant that will be validated to see whether or not the class prepends module SimpleCommand::ClassMethods.
98
+ #
99
+ # @return [Boolean] true if klass_constant prepends Module SimpleCommand::ClassMethods, false otherwise.
100
+ #
101
+ # @!visibility public
102
+ def is_simple_command?(klass_constant)
103
+ klass_constant.eigenclass.included_modules.include? SimpleCommand::ClassMethods
104
+ end
114
105
 
115
- # Runs the command given the parameters and returns the result.
116
- #
117
- # @param klass_constant [String] a class constant that will be called.
118
- # @param parameters [Array] an array of parameters to pass to the command that will be called.
119
- #
120
- # @return [Object] returns the object (if any) that results from calling the command.
121
- #
122
- # @!visibility public
123
- def run_command(klass_constant, parameters)
124
- klass_constant.call(*parameters)
125
- #rescue NameError
126
- # raise NameError.new("Class \"#{klass_constant}\" does not respond_to? method ::call.")
127
- end
106
+ # Runs the command given the parameters and returns the result.
107
+ #
108
+ # @param klass_constant [String] a class constant that will be called.
109
+ # @param parameters [Array] an array of parameters to pass to the command that will be called.
110
+ #
111
+ # @return [Object] returns the object (if any) that results from calling the command.
112
+ #
113
+ # @!visibility public
114
+ def run_command(klass_constant, parameters)
115
+ klass_constant.call(*parameters)
116
+ # rescue NameError
117
+ # raise NameError.new("Class \"#{klass_constant}\" does not respond_to? method ::call.")
128
118
  end
129
- end
119
+ end
120
+ end
130
121
  end
@@ -1,232 +1,222 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  # Tasks to play with certain klass_transform module members
3
5
 
4
-
5
6
  desc 'Test to_class_string'
6
7
  task :to_class_string do
7
- require "colorize"
8
- require "simple_command_dispatcher"
9
-
10
- class Test
11
- prepend SimpleCommand::KlassTransform
12
- end
13
-
14
- puts "Testing SimpleCommand::KlassTransform#to_class_String...\n".cyan
15
- puts "Enter a blank line to exit.".cyan
16
- loop do
17
- puts "\nUsage: \"-c [class], -o [options]\" where class = String or Symbol and options = Hash".cyan
18
- puts "\n\t Examples:"
19
- print "\n\t\t-c \"my_class\" -o { class_camelize: true }".cyan
20
- print "\n\t\t-c :MyClass -o { class_camelize: false }".cyan
21
-
22
- print "\n=> "
23
-
24
- input = STDIN.gets.chomp
25
- break if input.empty?
26
-
27
- input = clean_input(input)
28
-
29
- klass = get_option_class(input)
30
- if klass.nil? || klass.empty?
31
- print "=> Error: Class not a String or Symbol\n".red
32
- next
33
- elsif !klass.is_a?(String) && ! klass.is_a?(Symbol)
34
- print "=> Error: Class not a String or Symbol\n".red
35
- next
36
- end
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
37
38
 
38
- options_hash = get_options_hash(input)
39
+ options_hash = get_options_hash(input)
39
40
 
40
- options_hash = { class_camelize: true }.merge(options_hash || {})
41
+ options_hash = { class_camelize: true }.merge(options_hash || {})
41
42
 
42
- puts "\nCalling to_class_string with the following parameters: class: #{klass.class}, options: #{options_hash.class}".cyan
43
+ puts "\nCalling to_class_string with the following parameters: class: #{klass.class}, options: #{options_hash.class}".cyan
43
44
 
44
- print "\nSuccess: => #to_class_String(#{klass}, #{options_hash}) => #{Test.new.to_class_string(klass, options_hash)}\n".green
45
- end
45
+ print "\nSuccess: => #to_class_String(#{klass}, #{options_hash}) => #{Test.new.to_class_string(klass,
46
+ options_hash)}\n".green
47
+ end
46
48
 
47
- print
48
- print 'Done'.yellow
49
- print
49
+ print
50
+ print 'Done'.yellow
51
+ print
50
52
  end
51
53
 
52
-
53
54
  desc 'Test to_modules_string'
54
55
  task :to_modules_string do
55
- require "colorize"
56
- require "simple_command_dispatcher"
57
-
58
- class Test
59
- prepend SimpleCommand::KlassTransform
60
- end
61
-
62
- puts "Testing SimpleCommand::KlassTransform#to_modules_string...\n".cyan
63
- puts "Enter a blank line to exit.".cyan
64
- loop do
65
- puts "\nUsage: \"-m [modules], -o [options]\" where modules = Hash, Array or String and options = Hash".cyan
66
- puts "\n\t Examples:"
67
- print "\n\t\t-m \"Module1::Module2::Module3\" -o { modules_camelize: false }".cyan
68
- print "\n\t\t-m [:module1, :module2, :module3] -o { modules_camelize: true }".cyan
69
- print "\n\t\t-m {api: :api, app: :crazy_buttons, version: :v1} -o { modules_camelize: true }".cyan
70
-
71
- print "\n=> "
72
-
73
- input = STDIN.gets.chomp
74
- break if input.empty?
75
-
76
- input = clean_input(input)
77
-
78
- modules = get_option_modules(input)
79
- p modules.class
80
- if modules.nil? || modules.empty?
81
- print "=> Error: Modules not a Hash, Array or String\n".red
82
- next
83
- elsif !modules.is_a?(Hash) && !modules.is_a?(Array) && !modules.is_a?(String)
84
- print "=> Error: Modules not a Hash, Array or String\n".red
85
- next
86
- end
87
-
88
- options_hash = get_options_hash(input)
89
- options_hash = { module_camelize: true }.merge(options_hash || {})
90
-
91
- puts "\nCalling to_modules_string with the following parameters: modules: #{modules}, type: #{modules.class}, options: #{options_hash}, type: #{options_hash.class}...".cyan
92
-
93
- puts "\nSuccess: => #to_modules_string(#{modules}, #{options_hash}) => #{Test.new.to_modules_string(modules, options_hash)}\n".green
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
94
87
  end
95
88
 
96
- print
97
- print 'Done'.yellow
98
- print
89
+ options_hash = get_options_hash(input)
90
+ options_hash = { module_camelize: true }.merge(options_hash || {})
99
91
 
100
- end
92
+ puts "\nCalling to_modules_string with the following parameters: modules: #{modules}, type: #{modules.class}, options: #{options_hash}, type: #{options_hash.class}...".cyan
101
93
 
94
+ puts "\nSuccess: => #to_modules_string(#{modules}, #{options_hash}) => #{Test.new.to_modules_string(modules,
95
+ options_hash)}\n".green
96
+ end
102
97
 
103
- #
104
- #
105
- #
98
+ print
99
+ print 'Done'.yellow
100
+ print
101
+ end
106
102
 
107
103
  desc 'Test to_constantized_class_string'
108
104
  task :to_constantized_class_string do
109
- require "colorize"
110
- require "simple_command_dispatcher"
111
-
112
- class Test
113
- prepend SimpleCommand::KlassTransform
114
- end
115
-
116
- puts "Testing SimpleCommand::KlassTransform#to_constantized_class_string...\n".cyan
117
- puts "Enter a blank line to exit.".cyan
118
- loop do
119
- puts "\nUsage: \"-c [class] -m [modules], -o [options]\" where class = Symbol or String, modules = Hash, Array or String and options = Hash".cyan
120
- puts "\n\t Examples:"
121
- print "\n\t\t-c :MyClass -m \"Module1::Module2::Module3\" -o { modules_camelize: false }".cyan
122
- print "\n\t\t-c \"my_class\" -m [:module1, :module2, :module3] -o { modules_camelize: true }".cyan
123
- print "\n\t\t-c :myClass -m {api: :api, app: :crazy_buttons, version: :v1} -o { modules_camelize: true }".cyan
124
-
125
- print "\n=> "
126
-
127
- input = STDIN.gets.chomp
128
- break if input.empty?
129
-
130
- input = clean_input(input)
131
-
132
- klass = get_option_class(input)
133
- if klass.nil? || klass.empty?
134
- print "=> Error: Class not a String or Symbol\n".red
135
- next
136
- elsif !klass.is_a?(String) && ! klass.is_a?(Symbol)
137
- print "=> Error: Class not a String or Symbol\n".red
138
- next
139
- end
140
-
141
- modules = get_option_modules(input)
142
- if modules.nil? || modules.empty?
143
- print "=> Error: Modules not a Hash, Array or String\n".red
144
- next
145
- elsif !modules.is_a?(Hash) && !modules.is_a?(Array) && !modules.is_a?(String)
146
- print "=> Error: Modules not a Hash, Array or String\n".red
147
- next
148
- end
149
-
150
- options_hash = get_options_hash(input)
151
- options_hash = { class_camelize: true, module_camelize: true }.merge(options_hash || {})
152
-
153
- 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
154
-
155
- puts "\nSuccess: => #to_constantized_class_string(#{klass}, #{modules}, #{options_hash}) => #{Test.new.to_constantized_class_string(klass, modules, options_hash)}\n".green
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
156
135
  end
157
136
 
158
- print
159
- print 'Done'.yellow
160
- print
161
- end
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 || {})
162
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
163
160
 
164
161
  #
165
162
  # Helper methods
166
- #
163
+ #
167
164
 
168
165
  def clean_input(input)
169
- # Place a space before every dash that is not separated by a space.
170
- input = input.gsub(/-c/, " -c ").gsub(/-m/, " -m ").gsub(/-o/, " -o ")
171
- input = input.gsub(/"/, " \" ").gsub(/\s+/, " ").strip
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
172
169
 
173
- puts "=> keyboard input after clean_input => #{input}".magenta
170
+ puts "=> keyboard input after clean_input => #{input}".magenta
174
171
 
175
- input
172
+ input
176
173
  end
177
174
 
178
175
  def get_option_class(options)
179
- if options.nil? || options.empty?
180
- return ""
181
- end
182
- options_options = options[/-c\s*([:"].+?(["\s-]||$?))($|\s+|-)/m,1]
176
+ return '' if options.nil? || options.empty?
177
+
178
+ options_options = options[/-c\s*([:"].+?(["\s-]||$?))($|\s+|-)/m, 1]
183
179
 
184
- return "" if options_options.nil?
180
+ return '' if options_options.nil?
185
181
 
186
- options_options = options_options.gsub(/("|')+/, "")
187
- klass = options_options.strip.gsub(/\s+/, " ")
182
+ options_options = options_options.gsub(/("|')+/, '')
183
+ klass = options_options.strip.gsub(/\s+/, ' ')
188
184
 
189
- puts "=> class after get_option_class => #{klass}".magenta
185
+ puts "=> class after get_option_class => #{klass}".magenta
190
186
 
191
- klass
187
+ klass
192
188
  end
193
189
 
194
190
  def get_options_hash(options)
195
- if options.nil? || options.empty?
196
- return {}
197
- end
198
- options_options = options[/-o\s*([{].+?([}\s-]$?))($|\s+|-)/m,1]
191
+ return {} if options.nil? || options.empty?
192
+
193
+ options_options = options[/-o\s*([{].+?([}\s-]$?))($|\s+|-)/m, 1]
199
194
 
200
- return {} if options_options.nil?
195
+ return {} if options_options.nil?
201
196
 
202
- puts "=> options after get_options_hash => #{options_options}".magenta
197
+ puts "=> options after get_options_hash => #{options_options}".magenta
203
198
 
204
- begin
205
- eval(options_options)
206
- rescue
207
- {}
208
- end
199
+ begin
200
+ eval(options_options)
201
+ rescue StandardError
202
+ {}
203
+ end
209
204
  end
210
205
 
211
206
  def get_option_modules(modules)
212
- if modules.nil? || modules.empty?
213
- return ""
214
- end
207
+ return '' if modules.nil? || modules.empty?
215
208
 
216
- extracted_modules = modules[/-m\s*([\[{"].+?(["}\]\s-]$?))($|\s+|-)/m,1]
209
+ extracted_modules = modules[/-m\s*([\[{"].+?(["}\]\s-]$?))($|\s+|-)/m, 1]
217
210
 
218
- return "" if extracted_modules.nil?
211
+ return '' if extracted_modules.nil?
219
212
 
220
- extracted_modules = extracted_modules.strip.gsub(/\s+/, " ")
213
+ extracted_modules = extracted_modules.strip.gsub(/\s+/, ' ')
221
214
 
222
- puts "=> modules after get_option_modules => #{extracted_modules}".magenta
215
+ puts "=> modules after get_option_modules => #{extracted_modules}".magenta
223
216
 
224
- begin
225
- eval(extracted_modules)
226
- rescue
227
- ""
228
- end
217
+ begin
218
+ eval(extracted_modules)
219
+ rescue StandardError
220
+ ''
221
+ end
229
222
  end
230
-
231
-
232
-