Class: Plywood::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/plywood/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, command) ⇒ Command

Returns a new instance of Command.



8
9
10
11
12
13
# File 'lib/plywood/command.rb', line 8

def initialize(name, command)
  @name = name.to_s
  @command = command.to_s
  @err, @err_writer = build_pipe(:err)
  @out, @out_writer = build_pipe(:out)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/plywood/command.rb', line 5

def command
  @command
end

#errObject (readonly)

Returns the value of attribute err.



6
7
8
# File 'lib/plywood/command.rb', line 6

def err
  @err
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/plywood/command.rb', line 5

def name
  @name
end

#outObject (readonly)

Returns the value of attribute out.



6
7
8
# File 'lib/plywood/command.rb', line 6

def out
  @out
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/plywood/command.rb', line 6

def pid
  @pid
end

Instance Method Details

#iosObject



19
20
21
# File 'lib/plywood/command.rb', line 19

def ios
  [err, out]
end

#runObject



23
24
25
26
27
# File 'lib/plywood/command.rb', line 23

def run
  @pid = ::Process.spawn(@command, err: @err_writer, out: @out_writer)
  @err_writer.puts "started with pid #{@pid}"
  self
end

#to_sObject



15
16
17
# File 'lib/plywood/command.rb', line 15

def to_s
  "#{name} `#{@command}`"
end