Class: Gat::Action::Base
- Inherits:
-
Object
- Object
- Gat::Action::Base
- Includes:
- Interpreter
- Defined in:
- lib/gat/action/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#error ⇒ Object
Returns the value of attribute error.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#exit_level ⇒ Object
Returns the value of attribute exit_level.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#onfail ⇒ Object
Returns the value of attribute onfail.
-
#onfail_callback ⇒ Object
Returns the value of attribute onfail_callback.
-
#onfail_message ⇒ Object
Returns the value of attribute onfail_message.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#output ⇒ Object
Returns the value of attribute output.
-
#parsed_syntax ⇒ Object
Returns the value of attribute parsed_syntax.
-
#status ⇒ Object
Returns the value of attribute status.
-
#times ⇒ Object
Returns the value of attribute times.
Class Method Summary collapse
-
.get_current_action ⇒ Object
Get the current action.
Instance Method Summary collapse
- #execute ⇒ Object
-
#execute? ⇒ Boolean
Execute? Method check if action must be executed.
-
#initialize(name, config, operation) ⇒ Base
constructor
A new instance of Base.
Methods included from Interpreter
#interpreter_parameter, #interpreter_parameters, #interpreter_shell_command
Constructor Details
#initialize(name, config, operation) ⇒ Base
Returns a new instance of Base.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gat/action/base.rb', line 97 def initialize(name, config, operation) operation.gatget.logger.log("trace", "action", "Initialize action #{ self.class } @#{ name }") @times = Hash.new @times['init'] = Time.now @operation = operation @config = config @name = name @description = config['description'] || "Another Action named #{ name }" @flags = config['flags'] || [ ] @output = '' @error = nil @onfail = config['onfail'] || 'abort' @onfail_message = config['onfail_message'] @onfail_callback = config['onfail_callback'] @@current_action = self end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
70 71 72 |
# File 'lib/gat/action/base.rb', line 70 def argument @argument end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
68 69 70 |
# File 'lib/gat/action/base.rb', line 68 def config @config end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
71 72 73 |
# File 'lib/gat/action/base.rb', line 71 def description @description end |
#error ⇒ Object
Returns the value of attribute error.
73 74 75 |
# File 'lib/gat/action/base.rb', line 73 def error @error end |
#errors ⇒ Object
Returns the value of attribute errors.
78 79 80 |
# File 'lib/gat/action/base.rb', line 78 def errors @errors end |
#exit_level ⇒ Object
Returns the value of attribute exit_level.
79 80 81 |
# File 'lib/gat/action/base.rb', line 79 def exit_level @exit_level end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
72 73 74 |
# File 'lib/gat/action/base.rb', line 72 def flags @flags end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
69 70 71 |
# File 'lib/gat/action/base.rb', line 69 def name @name end |
#onfail ⇒ Object
Returns the value of attribute onfail.
85 86 87 |
# File 'lib/gat/action/base.rb', line 85 def onfail @onfail end |
#onfail_callback ⇒ Object
Returns the value of attribute onfail_callback.
87 88 89 |
# File 'lib/gat/action/base.rb', line 87 def onfail_callback @onfail_callback end |
#onfail_message ⇒ Object
Returns the value of attribute onfail_message.
86 87 88 |
# File 'lib/gat/action/base.rb', line 86 def @onfail_message end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
67 68 69 |
# File 'lib/gat/action/base.rb', line 67 def operation @operation end |
#output ⇒ Object
Returns the value of attribute output.
77 78 79 |
# File 'lib/gat/action/base.rb', line 77 def output @output end |
#parsed_syntax ⇒ Object
Returns the value of attribute parsed_syntax.
83 84 85 |
# File 'lib/gat/action/base.rb', line 83 def parsed_syntax @parsed_syntax end |
#status ⇒ Object
Returns the value of attribute status.
81 82 83 |
# File 'lib/gat/action/base.rb', line 81 def status @status end |
#times ⇒ Object
Returns the value of attribute times.
76 77 78 |
# File 'lib/gat/action/base.rb', line 76 def times @times end |
Class Method Details
.get_current_action ⇒ Object
Get the current action
92 93 94 |
# File 'lib/gat/action/base.rb', line 92 def self.get_current_action @@current_action end |
Instance Method Details
#execute ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/gat/action/base.rb', line 119 def execute if self.execute? self.run #self.set_outputs unless self.exit_level == 0 self.operation.gatget.logger.log("warning", "action_error", "#{self.error}") self.operation.gatget.logger.log("warning", "action_error", "Action #{ self.name } finished with status #{self.exit_level}") if self.onfail_callback self.operation.gatget.send(self.onfail_callback) end if self.onfail == 'abort' self.operation.gatget.logger.log('error', 'action_execute', "Action #{ self.name } abort Gatget") self.operation.status = 'fail' raise GatgetProcessException.new(self.error, "execute_action", self. ? {:message => self.} : {} ) end end end @times['end'] = Time.now end |
#execute? ⇒ Boolean
Execute? Method check if action must be executed. It test the follow conditions If flags is set, check that all flags are true If operation state is to abort or skip actions, skip actions
152 153 154 |
# File 'lib/gat/action/base.rb', line 152 def execute? flags_ok? and status_ok? end |