Module: SimpleCommandDispatcher
- Defined in:
- lib/simple_command_dispatcher/configuration.rb,
lib/simple_command_dispatcher.rb,
lib/simple_command_dispatcher/version.rb,
lib/simple_command_dispatcher/commands/utils.rb,
lib/simple_command_dispatcher/commands/errors.rb,
lib/simple_command_dispatcher/helpers/camelize.rb,
lib/simple_command_dispatcher/helpers/trim_all.rb,
lib/simple_command_dispatcher/services/command_service.rb,
lib/simple_command_dispatcher/commands/command_callable.rb,
lib/simple_command_dispatcher/services/command_namespace_service.rb,
lib/simple_command_dispatcher/errors/invalid_class_constant_error.rb,
lib/simple_command_dispatcher/errors/required_class_method_missing_error.rb
Overview
This is the configuration for SimpleCommandDispatcher.
Defined Under Namespace
Modules: Commands, Errors, Helpers, Services Classes: Configuration
Constant Summary collapse
- VERSION =
'4.1.0'
Class Attribute Summary collapse
-
.configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Class Method Summary collapse
-
.call(command:, command_namespace: {}, request_params: nil) ⇒ Object
Calls a Command given the command name, the namespace (modules) the command belongs to and the (request) parameters to pass to the command.
-
.configure {|Configuration| ... } ⇒ Configuration
Configures SimpleCommandDispatcher by yielding the configuration object to the block.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/simple_command_dispatcher/configuration.rb', line 6 def configuration @configuration end |
Class Method Details
.call(command:, command_namespace: {}, request_params: nil) ⇒ Object
Calls a Command given the command name, the namespace (modules) the command belongs to and the (request) parameters to pass to the command.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/simple_command_dispatcher.rb', line 53 def call(command:, command_namespace: {}, request_params: nil) # Create a constantized class from our command and command_namespace... constantized_class_object = Services::CommandService.new(command:, command_namespace:).to_class validate_command!(constantized_class_object) # We know we have a valid command class object if we get here. All we need to do is call the .call # class method, pass the request_params arguments depending on the request_params data type, and # return the results. call_command(constantized_class_object:, request_params:) end |
.configure {|Configuration| ... } ⇒ Configuration
Configures SimpleCommandDispatcher by yielding the configuration object to the block.
SimpleCommandDispatcher.configure do |config|
config.some_option = 'some value'
end
18 19 20 21 22 23 24 |
# File 'lib/simple_command_dispatcher/configuration.rb', line 18 def configure self.configuration ||= Configuration.new yield(configuration) if block_given? configuration end |