Module: Conductor
- Defined in:
- lib/conductor.rb,
lib/conductor/env.rb,
lib/conductor/config.rb,
lib/conductor/filter.rb,
lib/conductor/script.rb,
lib/conductor/command.rb,
lib/conductor/version.rb,
lib/conductor/condition.rb
Overview
Main Conductor module
Defined Under Namespace
Modules: Env Classes: Command, Condition, Config, Filter, Script
Constant Summary collapse
- VERSION =
'1.0.38'
Class Attribute Summary collapse
-
.original_input ⇒ Object
Returns the value of attribute original_input.
-
.stdin ⇒ String
Return STDIN value, reading from STDIN if needed.
Class Method Summary collapse
-
.conduct(tracks, res = nil, condition = nil) ⇒ Array
Main function to parse conditions and execute actions.
-
.execute_track(track) ⇒ Object
Execute commands/scripts in the track.
Class Attribute Details
.original_input ⇒ Object
Returns the value of attribute original_input.
27 28 29 |
# File 'lib/conductor.rb', line 27 def original_input @original_input end |
.stdin ⇒ String
Return STDIN value, reading from STDIN if needed
35 36 37 38 |
# File 'lib/conductor.rb', line 35 def stdin warn "input on STDIN required" unless ENV["CONDUCTOR_TEST"] || $stdin.stat.size.positive? || $stdin.fcntl(Fcntl::F_GETFL, 0).zero? @stdin ||= $stdin.read.force_encoding("utf-8") end |
Class Method Details
.conduct(tracks, res = nil, condition = nil) ⇒ Array
Main function to parse conditions and
execute actions. Executes recursively for
sub-tracks.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/conductor.rb', line 94 def conduct(tracks, res = nil, condition = nil) tracks.each do |track| cond = Condition.new(track[:condition]) next unless cond.true? # Build "matched condition" message title = track[:title] || track[:condition] condition ||= [""] condition << title condition.push(track.key?(:continue) ? " -> " : ", ") res = execute_track(track) if track[:tracks] ts = track[:tracks] res, condition = conduct(ts, res, condition) next if res.nil? end break unless track[:continue] end if res&.strip == Conductor.original_input.strip [nil, "No change in output"] else [res, condition] end end |
.execute_track(track) ⇒ Object
Execute commands/scripts in the track
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/conductor.rb', line 47 def execute_track(track) if track[:sequence] track[:sequence].each do |cmd| if cmd[:script] script = Script.new(cmd[:script]) res = script.run elsif cmd[:command] command = Command.new(cmd[:command]) res = command.run elsif cmd[:filter] filter = Filter.new(cmd[:filter]) res = filter.process end Conductor.stdin = res unless res.nil? end elsif track[:script] script = Script.new(track[:script]) Conductor.stdin = script.run elsif track[:command] command = Command.new(track[:command]) Conductor.stdin = command.run elsif track[:filter] filter = Filter.new(track[:filter]) Conductor.stdin = filter.process end Conductor.stdin end |