Module: Domainic::Command::ClassMethods
- Defined in:
- lib/domainic/command/class_methods.rb
Overview
Class methods that are extended onto any class that includes Domainic::Command. These methods provide the DSL for defining command inputs and outputs, as well as class-level execution methods.
Instance Method Summary collapse
-
#accepts_arguments_matching(input_context_class) ⇒ void
Specifies an external input context class for the command.
-
#argument(name, *type_validator_and_description, **options) ⇒ void
Defines an input argument for the command.
-
#call(**context) ⇒ Result
Executes the command with the given context, handling any errors.
-
#call!(**context) ⇒ Result
Executes the command with the given context, raising any errors.
-
#output(name, *type_validator_and_description, **options) ⇒ void
Defines an output field for the command.
-
#returns_data_matching(output_context_class) ⇒ void
Specifies an external output context class for the command.
Instance Method Details
#accepts_arguments_matching(input_context_class) ⇒ void
This method returns an undefined value.
Specifies an external input context class for the command
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/domainic/command/class_methods.rb', line 26 def accepts_arguments_matching(input_context_class) unless input_context_class < Context::InputContext raise ArgumentError, 'Input context class must be a subclass of Context::InputContext' end # @type self: Class & ClassMethods @input_context_class = begin const_set(:InputContext, Class.new(input_context_class)) const_get(:InputContext) end end |
#argument(name, *type_validator_and_description, **options) ⇒ void
This method returns an undefined value.
Defines an input argument for the command
65 66 67 |
# File 'lib/domainic/command/class_methods.rb', line 65 def argument(...) input_context_class.argument(...) end |
#call(**context) ⇒ Result
Executes the command with the given context, handling any errors
75 76 77 78 |
# File 'lib/domainic/command/class_methods.rb', line 75 def call(**context) # @type self: Class & ClassMethods & InstanceMethods new.call(**context) end |
#call!(**context) ⇒ Result
Executes the command with the given context, raising any errors
87 88 89 90 |
# File 'lib/domainic/command/class_methods.rb', line 87 def call!(**context) # @type self: Class & ClassMethods & InstanceMethods new.call!(**context) end |
#output(name, *type_validator_and_description, **options) ⇒ void
This method returns an undefined value.
Defines an output field for the command
119 120 121 |
# File 'lib/domainic/command/class_methods.rb', line 119 def output(...) output_context_class.field(...) end |
#returns_data_matching(output_context_class) ⇒ void
This method returns an undefined value.
Specifies an external output context class for the command
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/domainic/command/class_methods.rb', line 130 def returns_data_matching(output_context_class) unless output_context_class < Context::OutputContext raise ArgumentError, 'Output context class must be a subclass of Context::OutputContext' end # @type self: Class & ClassMethods @output_context_class = begin const_set(:OutputContext, Class.new(output_context_class)) const_get(:OutputContext) end end |