Class: Pasqual::Command
- Inherits:
-
Object
- Object
- Pasqual::Command
- Defined in:
- lib/pasqual/command.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#host ⇒ Object
Returns the value of attribute host.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#program ⇒ Object
Returns the value of attribute program.
-
#status ⇒ Object
Returns the value of attribute status.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(program, username, password, host, port, name, file = nil) ⇒ Command
constructor
A new instance of Command.
- #success? ⇒ Boolean
Constructor Details
#initialize(program, username, password, host, port, name, file = nil) ⇒ Command
Returns a new instance of Command.
14 15 16 17 18 19 20 21 22 |
# File 'lib/pasqual/command.rb', line 14 def initialize(program, username, password, host, port, name, file = nil) self.program = program self.username = username self.password = password self.host = host self.port = port self.name = name self.file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def file @file end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def host @host end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def output @output end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def port @port end |
#program ⇒ Object
Returns the value of attribute program.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def program @program end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def status @status end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/pasqual/command.rb', line 11 def username @username end |
Class Method Details
.execute(program, username, password, host, port, name, file = nil) ⇒ Object
7 8 9 |
# File 'lib/pasqual/command.rb', line 7 def self.execute(program, username, password, host, port, name, file = nil) new(program, username, password, host, port, name, file).tap { |c| c.execute } end |
Instance Method Details
#execute ⇒ Object
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 51 52 53 54 55 56 57 |
# File 'lib/pasqual/command.rb', line 24 def execute outfile = Tempfile.new("pasqual-#{name}") outfile.sync = true process = ChildProcess.build program, *Arglist.args(username, password, host, port, name) process.io.stdout = process.io.stderr = outfile process.duplex = true if file # TODO: find out why piping to stdin doesn't work :( ENV['PGPASSWORD'] = password process.start if file && File.exist?(file) File.open file do |f| process.io.stdin.puts f.read process.io.stdin.flush end process.io.stdin.close elsif file process.io.stdin.puts file process.io.stdin.flush process.io.stdin.close end process.poll_for_exit(30) ENV['PGPASSWORD'] = nil outfile.rewind self.output = outfile.read self.status = process.exit_code end |
#success? ⇒ Boolean
59 60 61 |
# File 'lib/pasqual/command.rb', line 59 def success? status == 0 end |