module Psychic::Runner::BaseRunner
Constants
- DEFAULT_PARAMS_FILE
Attributes
cwd[R]
env[R]
hints[R]
known_tasks[R]
tasks[R]
Public Class Methods
included(base)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 47 def self.included(base) base.extend(ClassMethods) end
new(opts = {})
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 51 def initialize(opts = {}) @opts = opts init_attr(:cwd) { Dir.pwd } init_hints init_attr(:known_tasks) { self.class.known_tasks } init_attr(:tasks) { self.class.tasks } init_attr(:logger) { new_logger } init_attr(:env) { ENV.to_hash } init_attrs :cli, :interactive, :parameter_mode, :restore_mode, :dry_run @shell_opts = select_shell_opts @parameters = load_parameters(opts[:parameters]) end
Public Instance Methods
active?()
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 91 def active? self.class.magic_file_patterns.each do | pattern | return true unless Dir["#{@cwd}/#{pattern}"].empty? end self.class.magic_env_vars.each do | var | return true if ENV[var] end false end
build_task(task_name, *_args)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 78 def build_task(task_name, *_args) task_name = task_name.to_s task = task_for(task_name) task = task.call if task.respond_to? :call fail Psychic::Runner::TaskNotImplementedError, task_name if task.nil? task end
dry_run?()
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 101 def dry_run? @dry_run == true end
execute(command, *args)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 72 def execute(command, *args) full_cmd = [command, *args].join(' ') logger.info("Executing #{full_cmd}") shell.execute(full_cmd, @shell_opts) unless dry_run? end
execute_task(task_name, *args)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 86 def execute_task(task_name, *args) command = build_task(task_name, *args) execute(command, *args) end
known_task?(task_name)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 64 def known_task?(task_name) known_tasks.include?(task_name.to_s) end
task_for(task_name)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 68 def task_for(task_name) tasks[task_name] if tasks.include? task_name end
Private Instance Methods
init_attr(var) { || ... }
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 107 def init_attr(var) var_name = "@#{var}" var_value = @opts[var] var_value = yield if var_value.nil? && block_given? instance_variable_set(var_name, var_value) end
init_attrs(*vars)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 114 def init_attrs(*vars) vars.each do | var | init_attr var end end
init_hints()
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 120 def init_hints @hints = Psychic::Util.stringified_hash(@opts[:hints] || load_hints || {}) if @hints['options'] @opts.merge! Psychic::Util.symbolized_hash(@hints['options']) end end
load_hints()
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 132 def load_hints hints_file = Dir["#{@cwd}/psychic.{yaml,yml}"].first YAML.load(File.read(hints_file)) unless hints_file.nil? end
load_parameters(parameters)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 137 def load_parameters(parameters) if parameters.nil? || parameters.is_a?(String) load_parameters_file(parameters) else parameters end end
load_parameters_file(file = nil)
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 145 def load_parameters_file(file = nil) if file.nil? file ||= File.expand_path(DEFAULT_PARAMS_FILE, cwd) return {} unless File.exist? file end parameters = Psychic::Util.replace_tokens(File.read(file), @env) YAML.load(parameters) end
select_shell_opts()
click to toggle source
# File lib/psychic/runner/base_runner.rb, line 127 def select_shell_opts # Make sure to delete any option that isn't a MixLib::ShellOut option @opts.select { |key, _| Psychic::Shell::AVAILABLE_OPTIONS.include? key } end
to_ary()
click to toggle source
Blame Ruby’s flatten and Array(…) behavior…
# File lib/psychic/runner/base_runner.rb, line 155 def to_ary nil end
Also aliased as: to_a