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)
-
- (Object) parent
Returns the value of attribute parent.
-
- (Object) test
Returns the value of attribute test.
Instance Method Summary (collapse)
-
- (Boolean) api_context?
True if this command was executed using ActionCommand.execute_api.
-
- (Boolean) child_context?
True if this command is a child of another command.
-
- (ActionCommand::Result) execute(result)
Execute the logic of a command.
-
- (Object) execute_internal(result)
Override this method to implement the logic of your command.
-
- (Executable) initialize(args)
constructor
Do not call new directly, instead use ActionCommand#execute_…
-
- (Boolean) rails_context?
True if this command was executed using ActionCommand.execute_rails.
-
- (Boolean) rake_context?
True if this command was executed using ActionCommand.execute_rake.
-
- (Symbol) root_context
action was executed in, see the ActionCommand::CONTEXT_ constants.
-
- (Boolean) test_context?
True if this command was executed using ActionCommand.execute_test.
-
- (Object) testing {|context| ... }
Call this within a commands execution if you'd like to perform validations within the testing context.
Constructor Details
- (Executable) initialize(args)
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
- (Object) parent
Returns the value of attribute parent
8 9 10 |
# File 'lib/action_command/executable.rb', line 8 def parent @parent end |
- (Object) test
Returns the value of attribute test
8 9 10 |
# File 'lib/action_command/executable.rb', line 8 def test @test end |
Instance Method Details
- (Boolean) api_context?
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 |
- (Boolean) child_context?
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 |
- (ActionCommand::Result) execute(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 |
- (Object) execute_internal(result)
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 |
- (Boolean) rails_context?
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 |
- (Boolean) rake_context?
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 |
- (Symbol) root_context
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 |
- (Boolean) test_context?
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 |
- (Object) testing {|context| ... }
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 |