Class: ForemanMaintain::Executable
- Inherits:
-
Object
- Object
- ForemanMaintain::Executable
- Extended by:
- Concerns::Finders, Forwardable
- Defined in:
- lib/foreman_maintain/executable.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#__run__(execution) ⇒ Object
internal method called by executor.
- #abort!(message = '') ⇒ Object
-
#after_initialize ⇒ Object
public method to be overriden to perform after-initialization steps.
- #associated_feature ⇒ Object
-
#ensure_instance ⇒ Object
method defined both on object and class to ensure we work always with object even when the definitions provide us only class.
-
#eql?(other) ⇒ Boolean
To be able to call uniq on a set of steps to deduplicate the same steps inside the scenario.
- #executed? ⇒ Boolean
- #execution ⇒ Object
-
#fail!(message) ⇒ Object
make the step to fail: the failure is considered significant and the next steps should not continue.
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Executable
constructor
A new instance of Executable.
- #inspect ⇒ Object
- #matches_hash?(hash) ⇒ Boolean
-
#necessary? ⇒ Boolean
public method to be overriden: it can perform additional checks to say, if the step is actually necessary to run.
-
#next_steps ⇒ Object
next steps to be offered to the user after the step is run It can be added for example from the assert method.
-
#run ⇒ Object
public method to be overriden.
-
#say(message) ⇒ Object
update reporter about the current message.
- #set_abort(message) ⇒ Object
-
#set_fail(message) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #set_info_warn(message) ⇒ Object
- #set_param_variable(param_name, value) ⇒ Object
- #set_skip(message) ⇒ Object
- #set_status(status, message) ⇒ Object
- #set_warn(message) ⇒ Object
-
#setup_execution_state(execution) ⇒ Object
clean the execution-specific state to prepare for the next execution attempts.
-
#setup_params ⇒ Object
processes the params from provided options.
- #skip(message = '') ⇒ Object
-
#to_hash ⇒ Object
serialization methods.
- #update_from_hash(hash) ⇒ Object
-
#warn!(message) ⇒ Object
make the step a warning: this doesn’t indicate the whole scenario should not continue, but the user will be warned before proceeding.
Methods included from Concerns::Finders
check, detector, feature, find_all_scenarios, find_checks, find_procedures, find_scenarios, procedure
Constructor Details
#initialize(options = {}) ⇒ Executable
Returns a new instance of Executable.
12 13 14 15 16 17 |
# File 'lib/foreman_maintain/executable.rb', line 12 def initialize( = {}) @options = .inject({}) { |h, (k, v)| h.update(k.to_s => v) } @param_values = {} setup_params after_initialize end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/foreman_maintain/executable.rb', line 5 def @options end |
Class Method Details
.ensure_instance ⇒ Object
191 192 193 |
# File 'lib/foreman_maintain/executable.rb', line 191 def ensure_instance new end |
Instance Method Details
#__run__(execution) ⇒ Object
internal method called by executor
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/foreman_maintain/executable.rb', line 138 def __run__(execution) setup_execution_state(execution) unless skipped? run end rescue Error::Skip => e set_skip(e.) rescue Error::Abort => e set_abort(e.) end |
#abort!(message = '') ⇒ Object
81 82 83 |
# File 'lib/foreman_maintain/executable.rb', line 81 def abort!( = '') raise Error::Abort, end |
#after_initialize ⇒ Object
public method to be overriden to perform after-initialization steps
30 31 |
# File 'lib/foreman_maintain/executable.rb', line 30 def after_initialize end |
#associated_feature ⇒ Object
49 50 51 52 53 54 |
# File 'lib/foreman_maintain/executable.rb', line 49 def associated_feature return @associated_feature if defined? @associated_feature if [:for_feature] @associated_feature = feature([:for_feature]) end end |
#ensure_instance ⇒ Object
method defined both on object and class to ensure we work always with object even when the definitions provide us only class
151 152 153 |
# File 'lib/foreman_maintain/executable.rb', line 151 def ensure_instance self end |
#eql?(other) ⇒ Boolean
To be able to call uniq on a set of steps to deduplicate the same steps inside the scenario
21 22 23 |
# File 'lib/foreman_maintain/executable.rb', line 21 def eql?(other) self.class.eql?(other.class) && .eql?(other.) end |
#executed? ⇒ Boolean
117 118 119 |
# File 'lib/foreman_maintain/executable.rb', line 117 def executed? @_execution ? true : false end |
#execution ⇒ Object
121 122 123 |
# File 'lib/foreman_maintain/executable.rb', line 121 def execution @_execution || raise('Trying to get execution information before the run started happened') end |
#fail!(message) ⇒ Object
make the step to fail: the failure is considered significant and the next steps should not continue. The specific behaviour depends on the scenario it’s being used on. In check-sets scenario, the next steps of the same scenario might continue, while the following scenarios would be aborted.
67 68 69 |
# File 'lib/foreman_maintain/executable.rb', line 67 def fail!() raise Error::Fail, end |
#hash ⇒ Object
25 26 27 |
# File 'lib/foreman_maintain/executable.rb', line 25 def hash [self.class, ].hash end |
#inspect ⇒ Object
183 184 185 186 187 188 |
# File 'lib/foreman_maintain/executable.rb', line 183 def inspect ret = "#{self.class.name} label:#{label}" ret << " params: #{@param_values.inspect}" unless @param_values.empty? ret << " status: #{execution.status}" if executed? ret end |
#matches_hash?(hash) ⇒ Boolean
172 173 174 |
# File 'lib/foreman_maintain/executable.rb', line 172 def matches_hash?(hash) label == hash[:label] && @param_values == hash[:param_values] end |
#necessary? ⇒ Boolean
public method to be overriden: it can perform additional checks to say, if the step is actually necessary to run. For example an ‘Packages::Install` procedure would not be necessary when the package is already installed.
128 129 130 |
# File 'lib/foreman_maintain/executable.rb', line 128 def necessary? true end |
#next_steps ⇒ Object
next steps to be offered to the user after the step is run It can be added for example from the assert method
58 59 60 |
# File 'lib/foreman_maintain/executable.rb', line 58 def next_steps @next_steps ||= [] end |
#run ⇒ Object
public method to be overriden
113 114 115 |
# File 'lib/foreman_maintain/executable.rb', line 113 def run raise NotImplementedError end |
#say(message) ⇒ Object
update reporter about the current message
133 134 135 |
# File 'lib/foreman_maintain/executable.rb', line 133 def say() execution.update() end |
#set_abort(message) ⇒ Object
102 103 104 |
# File 'lib/foreman_maintain/executable.rb', line 102 def set_abort() set_status(:abort, ) end |
#set_fail(message) ⇒ Object
rubocop:disable Naming/AccessorMethodName
86 87 88 |
# File 'lib/foreman_maintain/executable.rb', line 86 def set_fail() set_status(:fail, ) end |
#set_info_warn(message) ⇒ Object
94 95 96 |
# File 'lib/foreman_maintain/executable.rb', line 94 def set_info_warn() set_status(:info_warning, ) end |
#set_param_variable(param_name, value) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/foreman_maintain/executable.rb', line 41 def set_param_variable(param_name, value) @param_values[param_name] = value if instance_variable_defined?("@#{param_name}") raise "Instance variable @#{param_name} already set" end instance_variable_set("@#{param_name}", value) end |
#set_skip(message) ⇒ Object
98 99 100 |
# File 'lib/foreman_maintain/executable.rb', line 98 def set_skip() set_status(:skipped, ) end |
#set_status(status, message) ⇒ Object
106 107 108 109 |
# File 'lib/foreman_maintain/executable.rb', line 106 def set_status(status, ) execution.status = status execution.output << if && !.empty? end |
#set_warn(message) ⇒ Object
90 91 92 |
# File 'lib/foreman_maintain/executable.rb', line 90 def set_warn() set_status(:warning, ) end |
#setup_execution_state(execution) ⇒ Object
clean the execution-specific state to prepare for the next execution attempts
157 158 159 160 |
# File 'lib/foreman_maintain/executable.rb', line 157 def setup_execution_state(execution) @_execution = execution @next_steps = [] end |
#setup_params ⇒ Object
processes the params from provided options
34 35 36 37 38 39 |
# File 'lib/foreman_maintain/executable.rb', line 34 def setup_params @options.(params.values.map(&:name).map(&:to_s)) params.each_value do |param| set_param_variable(param.name, param.process(@options[param.name.to_s])) end end |
#skip(message = '') ⇒ Object
77 78 79 |
# File 'lib/foreman_maintain/executable.rb', line 77 def skip( = '') raise Error::Skip, end |
#to_hash ⇒ Object
serialization methods
163 164 165 166 167 168 169 170 |
# File 'lib/foreman_maintain/executable.rb', line 163 def to_hash ret = { :label => label, :param_values => @param_values } if @_execution ret[:status] = @_execution.status ret[:output] = @_execution.output end ret end |
#update_from_hash(hash) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/foreman_maintain/executable.rb', line 176 def update_from_hash(hash) raise "The step is not matching the hash #{hash.inspect}" unless matches_hash?(hash) raise "Can't update step that was already executed" if @_execution @_execution = Runner::StoredExecution.new(self, :status => hash[:status], :output => hash[:output]) end |