Class: Runner
- Inherits:
-
Object
- Object
- Runner
- Defined in:
- lib/go_run/runner.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #exit_status ⇒ Object
-
#initialize(config) ⇒ Runner
constructor
A new instance of Runner.
- #requirement_fulfilled?(requirement) ⇒ Boolean
- #run(targets) ⇒ Object
- #run_command(command) ⇒ Object
- #run_target(target) ⇒ Object
Constructor Details
#initialize(config) ⇒ Runner
Returns a new instance of Runner.
4 5 6 7 8 |
# File 'lib/go_run/runner.rb', line 4 def initialize(config) @config = config @commands = [] @output = "" end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
2 3 4 |
# File 'lib/go_run/runner.rb', line 2 def commands @commands end |
Instance Method Details
#exit_status ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/go_run/runner.rb', line 73 def exit_status non_zero_exit_status = @commands.find { |c| c["exit_code"] != 0 } if non_zero_exit_status.nil? return 0 end return non_zero_exit_status["exit_code"] end |
#requirement_fulfilled?(requirement) ⇒ Boolean
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/go_run/runner.rb', line 61 def requirement_fulfilled?(requirement) if ENV.has_key? requirement["key"] return true elsif requirement.has_key? "default" ENV[requirement["key"]] = requirement["default"] return true else @output << "Environment variable #{requirement["key"]} not set\n" end return false end |
#run(targets) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/go_run/runner.rb', line 10 def run(targets) targets.each do |target| run_target(target) end @output end |
#run_command(command) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/go_run/runner.rb', line 52 def run_command(command) system(command) @commands << { "command" => command, "exit_code" => $?.exitstatus } $?.exitstatus end |
#run_target(target) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/go_run/runner.rb', line 17 def run_target(target) raise "Target '#{target}' not found in configuration" if not @config.has_key? target if @config[target].has_key? "group" @config[target]["group"].each do |group| run_target(group) end end if @config[target].has_key? "set" @config[target]["set"].each do |env_var| ENV[env_var["key"]] = env_var["value"] end end if @config[target].has_key? "requires" @config[target]["requires"].each do |requirement| if not requirement_fulfilled?(requirement) @output << "Failed to fulfill requirements for target '#{target}'\n" return end end end if @config[target].has_key? "call" @config[target]["call"].each do |call| run_target(call["target"]) end end if @config[target].has_key? "commands" @config[target]["commands"].each do |command| if run_command(command) != 0 @output << "Failed to run command '#{command}'\n" return end end end end |