Class: Evnt::Command
- Inherits:
-
Object
- Object
- Evnt::Command
- Defined in:
- lib/evnt/command.rb
Overview
Commands are used to run single tasks on the system. It’s like a controller on an MVC architecture without the communication with the client.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Attribute containings the list of command parameters.
Class Method Summary collapse
-
.default_options(options) ⇒ Object
This function sets the default options that should be used by the command.
-
.to_initialize_events(&block) ⇒ Object
This function sets the intitialize events function for the command.
-
.to_normalize_params(&block) ⇒ Object
This function sets the normalize params function for the command.
-
.to_validate_logic(&block) ⇒ Object
This function sets the validate logic function for the command.
-
.to_validate_params(&block) ⇒ Object
This function sets the validate params function for the command.
-
.validates(param, options) ⇒ Object
This function sets the single validation request for a command parameter.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
This function tells if the command is completed or not.
-
#error_codes ⇒ Object
This function returns the list of error codes of the command.
-
#error_messages ⇒ Object
This function returns the list of error messages of the command.
-
#errors ⇒ Object
This function returns the list of errors of the command.
-
#initialize(params = {}) ⇒ Command
constructor
The constructor is used to run a new command.
Constructor Details
#initialize(params = {}) ⇒ Command
The constructor is used to run a new command.
Attributes
-
params- The list of parameters for the command. -
_options- The list of options for the command.
Options
-
exceptions- Boolean value used to activate the throw of excetions. -
nullify_empty_params- Transform empty params to nil values so the validator
should consider them as nil values.
31 32 33 34 |
# File 'lib/evnt/command.rb', line 31 def initialize(params = {}) _init_command_data(params) _run_command_steps end |
Instance Attribute Details
#params ⇒ Object (readonly)
Attribute containings the list of command parameters.
15 16 17 |
# File 'lib/evnt/command.rb', line 15 def params @params end |
Class Method Details
.default_options(options) ⇒ Object
This function sets the default options that should be used by the command.
210 211 212 213 214 215 216 |
# File 'lib/evnt/command.rb', line 210 def () ||= {} .merge!() = define_method('_default_options', -> { return }) end |
.to_initialize_events(&block) ⇒ Object
This function sets the intitialize events function for the command.
243 244 245 |
# File 'lib/evnt/command.rb', line 243 def to_initialize_events(&block) define_method('_initialize_events', &block) end |
.to_normalize_params(&block) ⇒ Object
This function sets the normalize params function for the command.
228 229 230 |
# File 'lib/evnt/command.rb', line 228 def to_normalize_params(&block) define_method('_normalize_params', &block) end |
.to_validate_logic(&block) ⇒ Object
This function sets the validate logic function for the command.
238 239 240 |
# File 'lib/evnt/command.rb', line 238 def to_validate_logic(&block) define_method('_validate_logic', &block) end |
.to_validate_params(&block) ⇒ Object
This function sets the validate params function for the command.
233 234 235 |
# File 'lib/evnt/command.rb', line 233 def to_validate_params(&block) define_method('_validate_params', &block) end |
.validates(param, options) ⇒ Object
This function sets the single validation request for a command parameter.
219 220 221 222 223 224 225 |
# File 'lib/evnt/command.rb', line 219 def validates(param, ) @validations ||= [] @validations.push(param: param, options: ) command_validations = @validations define_method('_validations', -> { return command_validations }) end |
Instance Method Details
#completed? ⇒ Boolean
This function tells if the command is completed or not. The returned object should be a boolean value.
70 71 72 |
# File 'lib/evnt/command.rb', line 70 def completed? @state[:result] end |
#error_codes ⇒ Object
This function returns the list of error codes of the command. The returned object should be an array of integers.
62 63 64 |
# File 'lib/evnt/command.rb', line 62 def error_codes @state[:errors].map { |e| e[:code] } end |
#error_messages ⇒ Object
This function returns the list of error messages of the command. The returned object should be an array of strings.
54 55 56 |
# File 'lib/evnt/command.rb', line 54 def @state[:errors].map { |e| e[:message] } end |
#errors ⇒ Object
This function returns the list of errors of the command. The returned object should be an array of hashes with a message and a code value. The code value of hashes should be nil if code is not defined using the stop() function.
46 47 48 |
# File 'lib/evnt/command.rb', line 46 def errors @state[:errors] end |