Class: Shr::Command
- Inherits:
-
Object
- Object
- Shr::Command
- Defined in:
- lib/shr/command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(command, options = []) ⇒ Command
constructor
A new instance of Command.
- #release? ⇒ Boolean
- #to_proc ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
14 15 16 |
# File 'lib/shr/command.rb', line 14 def command @command end |
Instance Method Details
#exist? ⇒ Boolean
25 26 27 |
# File 'lib/shr/command.rb', line 25 def exist? Which::exist? @command.chomp('!') end |
#release? ⇒ Boolean
29 30 31 |
# File 'lib/shr/command.rb', line 29 def release? @command.end_with? '!' end |
#to_proc ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shr/command.rb', line 33 def to_proc Proc.new do |environment, command_out| if release? Open3.pipeline(self.to_s) [nil, nil] else io_r, io_w = IO.pipe = { :out => io_w } [:in] = command_out if command_out .merge!(environment) pid = spawn(self.to_s, ) watcher = Process.detach(pid) io_w.close [io_r, watcher] end end end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/shr/command.rb', line 21 def to_s [command, @options].join(' ') end |