Class: Pasqual::Command
- Inherits:
-
Object
- Object
- Pasqual::Command
- Defined in:
- lib/pasqual/command.rb
Instance Attribute Summary collapse
-
#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) ⇒ Command
constructor
A new instance of Command.
- #success? ⇒ Boolean
Constructor Details
#initialize(program, username, password, host, port, name) ⇒ Command
Returns a new instance of Command.
14 15 16 17 18 19 20 21 |
# File 'lib/pasqual/command.rb', line 14 def initialize(program, username, password, host, port, name) self.program = program self.username = username self.password = password self.host = host self.port = port self.name = name end |
Instance Attribute Details
#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) ⇒ Object
7 8 9 |
# File 'lib/pasqual/command.rb', line 7 def self.execute(program, username, password, host, port, name) new(program, username, password, host, port, name).tap { |c| c.execute } end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pasqual/command.rb', line 23 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 if password # TODO: find out why piping to stdin doesn't work :( ENV['PGPASSWORD'] = password process.start process.poll_for_exit(30) ENV['PGPASSWORD'] = nil else process.start process.poll_for_exit(30) end outfile.rewind self.output = outfile.read self.status = process.exit_code end |
#success? ⇒ Boolean
48 49 50 |
# File 'lib/pasqual/command.rb', line 48 def success? status == 0 end |