# File lib/foreman_maintain/executable.rb, line 114 def ensure_instance new end
# File lib/foreman_maintain/executable.rb, line 10 def initialize(options = {}) @options = options.inject({}) { |h, (k, v)| h.update(k.to_s => v) } @param_values = {} setup_params after_initialize end
internal method called by executor
# File lib/foreman_maintain/executable.rb, line 95 def __run__(execution) setup_execution_state(execution) run end
public method to be overriden to perform after-initialization steps
# File lib/foreman_maintain/executable.rb, line 28 def after_initialize; end
method defined both on object and class to ensure we work always with object even when the definitions provide us only class
# File lib/foreman_maintain/executable.rb, line 102 def ensure_instance self end
To be able to call uniq on a set of steps to deduplicate the same steps inside the scenario
# File lib/foreman_maintain/executable.rb, line 19 def eql?(other) self.class.eql?(other.class) && options.eql?(other.options) end
# File lib/foreman_maintain/executable.rb, line 64 def execution if @_execution @_execution else raise 'Trying to get execution information before the run started happened' end end
# File lib/foreman_maintain/executable.rb, line 79 def fail!(message) execution.status = :fail execution.output << message end
# File lib/foreman_maintain/executable.rb, line 23 def hash [self.class, options].hash end
public method to be overriden: it can perform additional checks to say, if the step is actually necessary to run. For example an `InstallPackage` procedure would not be necessary when the package is already installed.
# File lib/foreman_maintain/executable.rb, line 75 def necessary? true end
next steps to be offered to the user after the step is run It can be added for example from the assert method
# File lib/foreman_maintain/executable.rb, line 55 def next_steps @next_steps ||= [] end
public method to be overriden
# File lib/foreman_maintain/executable.rb, line 60 def run raise NotImplementedError end
update reporter about the current message
# File lib/foreman_maintain/executable.rb, line 90 def say(message) execution.update(message) end
# File lib/foreman_maintain/executable.rb, line 38 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
clean the execution-specific state to prepare for the next execution attempts
# File lib/foreman_maintain/executable.rb, line 108 def setup_execution_state(execution) @_execution = execution @next_steps = [] end
processes the params from provided options
# File lib/foreman_maintain/executable.rb, line 31 def setup_params @options.validate_options!(params.values.map(&:name).map(&:to_s)) params.values.each do |param| set_param_variable(param.name, param.process(@options[param.name.to_s])) end end
# File lib/foreman_maintain/executable.rb, line 84 def warn!(message) execution.status = :warning execution.output << message end