Module: Psychic::Runner::BaseRunner
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- DEFAULT_PARAMS_FILE =
'psychic-parameters.yaml'
Constants included
from Shell
Shell::AVAILABLE_OPTIONS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
#log_level=, #logger, #new_logger
Methods included from Shell
#shell
Instance Attribute Details
#cwd ⇒ Object
Returns the value of attribute cwd.
9
10
11
|
# File 'lib/psychic/runner/base_runner.rb', line 9
def cwd
@cwd
end
|
#env ⇒ Object
Returns the value of attribute env.
9
10
11
|
# File 'lib/psychic/runner/base_runner.rb', line 9
def env
@env
end
|
#hints ⇒ Object
Returns the value of attribute hints.
9
10
11
|
# File 'lib/psychic/runner/base_runner.rb', line 9
def hints
@hints
end
|
#known_tasks ⇒ Object
Returns the value of attribute known_tasks.
9
10
11
|
# File 'lib/psychic/runner/base_runner.rb', line 9
def known_tasks
@known_tasks
end
|
#tasks ⇒ Object
Returns the value of attribute tasks.
9
10
11
|
# File 'lib/psychic/runner/base_runner.rb', line 9
def tasks
@tasks
end
|
Class Method Details
.included(base) ⇒ Object
47
48
49
|
# File 'lib/psychic/runner/base_runner.rb', line 47
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#active? ⇒ Boolean
91
92
93
94
95
96
97
98
99
|
# 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) ⇒ Object
78
79
80
81
82
83
84
|
# 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? ⇒ Boolean
101
102
103
|
# File 'lib/psychic/runner/base_runner.rb', line 101
def dry_run?
@dry_run == true
end
|
#execute(command, *args) ⇒ Object
72
73
74
75
76
|
# 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) ⇒ Object
86
87
88
89
|
# 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
|
#initialize(opts = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# 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
|
#known_task?(task_name) ⇒ Boolean
64
65
66
|
# 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) ⇒ Object
68
69
70
|
# File 'lib/psychic/runner/base_runner.rb', line 68
def task_for(task_name)
tasks[task_name] if tasks.include? task_name
end
|