Class: Ukiryu::Action::Base Abstract
- Inherits:
-
Object
- Object
- Ukiryu::Action::Base
- Defined in:
- lib/ukiryu/action/base.rb
Overview
This class is abstract.
Abstract base class for action classes
Action classes represent executable commands and provide a fluent interface for building and executing commands.
This is an alternative pattern to using options objects directly.
Class Attribute Summary collapse
-
.command_def ⇒ Hash
readonly
Get the command definition.
-
.command_name ⇒ Symbol
readonly
Get the command name.
-
.tool_class ⇒ Class
readonly
Get the associated tool class.
Instance Method Summary collapse
-
#command_def ⇒ Hash
Get the command definition.
-
#command_name ⇒ Symbol
Get the command name.
-
#initialize(tool_instance = nil) ⇒ Base
constructor
Create a new action.
-
#options ⇒ Options::Base
Create an options object for this action.
-
#run(options = {}, timeout:) ⇒ Response::Base
Execute this action with options.
Constructor Details
#initialize(tool_instance = nil) ⇒ Base
Create a new action
34 35 36 |
# File 'lib/ukiryu/action/base.rb', line 34 def initialize(tool_instance = nil) @tool = tool_instance || self.class.tool_class.new end |
Class Attribute Details
.command_def ⇒ Hash (readonly)
Get the command definition
23 24 25 |
# File 'lib/ukiryu/action/base.rb', line 23 def command_def @command_def end |
.command_name ⇒ Symbol (readonly)
Get the command name
18 19 20 |
# File 'lib/ukiryu/action/base.rb', line 18 def command_name @command_name end |
.tool_class ⇒ Class (readonly)
Get the associated tool class
28 29 30 |
# File 'lib/ukiryu/action/base.rb', line 28 def tool_class @tool_class end |
Instance Method Details
#command_def ⇒ Hash
Get the command definition
73 74 75 |
# File 'lib/ukiryu/action/base.rb', line 73 def command_def self.class.command_def end |
#command_name ⇒ Symbol
Get the command name
66 67 68 |
# File 'lib/ukiryu/action/base.rb', line 66 def command_name self.class.command_name end |
#options ⇒ Options::Base
Create an options object for this action
59 60 61 |
# File 'lib/ukiryu/action/base.rb', line 59 def @tool.(self.class.command_name).new end |
#run(options = {}, timeout:) ⇒ Response::Base
Execute this action with options
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ukiryu/action/base.rb', line 43 def run( = {}, timeout:) # If options is a hash, create an options object if .is_a?(Hash) = @tool.(self.class.command_name) = .new .set() = end # Execute with the tool @tool.execute(self.class.command_name, , timeout: timeout) end |