Class: Conductor::Script
- Inherits:
-
Object
- Object
- Conductor::Script
- Defined in:
- lib/conductor/script.rb
Overview
Script runner
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(script) ⇒ Script
constructor
Initializes the given script.
-
#run ⇒ String
Execute the script.
Constructor Details
#initialize(script) ⇒ Script
Initializes the given script.
13 14 15 16 17 |
# File 'lib/conductor/script.rb', line 13 def initialize(script) parts = Shellwords.split(script) self.path = parts[0] self.args = parts[1..].join(" ") end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/conductor/script.rb', line 6 def args @args end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/conductor/script.rb', line 6 def path @path end |
Instance Method Details
#run ⇒ String
Execute the script
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/conductor/script.rb', line 58 def run stdin = Conductor.stdin unless /\$\{?file\}?/.match?(args) raise "Script path not defined" unless @path raise "Script not executable" unless File.executable?(@path) use_stdin = true if /\$\{?file\}?/.match?(args) use_stdin = false args.sub!(/\$\{?file\}?/, Env.env[:filepath]) else raise "No input" unless stdin end if use_stdin `echo #{Shellwords.escape(stdin.utf8)} | #{Env} #{@path} #{@args}` else `#{Env} #{@path} #{@args}` end end |