Class: ActionCommand::Executable
- Inherits:
-
Object
- Object
- ActionCommand::Executable
- Defined in:
- lib/action_command/executable.rb
Overview
Root class for action commands that can be executed by this library. Override execute_internal to implement one, call one of the variants of ActionCommand.execute_… to execute one.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
-
#api_context? ⇒ Boolean
True if this command was executed using ActionCommand.execute_api.
-
#child_context? ⇒ Boolean
True if this command is a child of another command.
-
#execute(result) ⇒ ActionCommand::Result
Execute the logic of a command.
-
#execute_internal(result) ⇒ Object
Override this method to implement the logic of your command.
-
#initialize(args) ⇒ Executable
constructor
Do not call new directly, instead use ActionCommand#execute_…
-
#rails_context? ⇒ Boolean
True if this command was executed using ActionCommand.execute_rails.
-
#rake_context? ⇒ Boolean
True if this command was executed using ActionCommand.execute_rake.
-
#root_context ⇒ Symbol
action was executed in, see the ActionCommand::CONTEXT_ constants.
-
#test_context? ⇒ Boolean
True if this command was executed using ActionCommand.execute_test.
-
#testing {|context| ... } ⇒ Object
Call this within a commands execution if you’d like to perform validations within the testing context.
Constructor Details
#initialize(args) ⇒ Executable
Do not call new directly, instead use ActionCommand#execute_… variants.
11 12 13 |
# File 'lib/action_command/executable.rb', line 11 def initialize(args) self.class.describe_io.process_input(self, args) end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/action_command/executable.rb', line 8 def parent @parent end |
#test ⇒ Object
Returns the value of attribute test.
8 9 10 |
# File 'lib/action_command/executable.rb', line 8 def test @test end |
Instance Method Details
#api_context? ⇒ Boolean
Returns true if this command was executed using ActionCommand.execute_api.
39 40 41 |
# File 'lib/action_command/executable.rb', line 39 def api_context? return root_context == ActionCommand::CONTEXT_API end |
#child_context? ⇒ Boolean
Returns true if this command is a child of another command.
45 46 47 |
# File 'lib/action_command/executable.rb', line 45 def child_context? return !parent.is_a?(Symbol) end |
#execute(result) ⇒ ActionCommand::Result
Execute the logic of a command. Should not usually be called directly. Command executors should call one of the ActionCommand.execute_… variants. Command implementors should override execute_internal.
54 55 56 57 58 |
# File 'lib/action_command/executable.rb', line 54 def execute(result) execute_internal(result) self.class.describe_io.process_output(self, result) return result end |
#execute_internal(result) ⇒ Object
Override this method to implement the logic of your command
75 76 77 |
# File 'lib/action_command/executable.rb', line 75 def execute_internal(result) end |
#rails_context? ⇒ Boolean
Returns true if this command was executed using ActionCommand.execute_rails.
29 30 31 |
# File 'lib/action_command/executable.rb', line 29 def rails_context? return root_context == ActionCommand::CONTEXT_RAILS end |
#rake_context? ⇒ Boolean
Returns true if this command was executed using ActionCommand.execute_rake.
34 35 36 |
# File 'lib/action_command/executable.rb', line 34 def rake_context? return root_context == ActionCommand::CONTEXT_RAKE end |
#root_context ⇒ Symbol
action was executed in, see the ActionCommand::CONTEXT_ constants.
17 18 19 20 21 |
# File 'lib/action_command/executable.rb', line 17 def root_context context = parent context = context.parent until context.is_a? Symbol return context end |
#test_context? ⇒ Boolean
Returns true if this command was executed using ActionCommand.execute_test.
24 25 26 |
# File 'lib/action_command/executable.rb', line 24 def test_context? return root_context == ActionCommand::CONTEXT_TEST end |
#testing {|context| ... } ⇒ Object
Call this within a commands execution if you’d like to perform validations within the testing context.
64 65 66 |
# File 'lib/action_command/executable.rb', line 64 def testing yield @test if @test end |