Class: Pasqual::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hostObject

Returns the value of attribute host.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def host
  @host
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def name
  @name
end

#outputObject

Returns the value of attribute output.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def output
  @output
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def password
  @password
end

#portObject

Returns the value of attribute port.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def port
  @port
end

#programObject

Returns the value of attribute program.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def program
  @program
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/pasqual/command.rb', line 11

def status
  @status
end

#usernameObject

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

#executeObject



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

Returns:

  • (Boolean)


48
49
50
# File 'lib/pasqual/command.rb', line 48

def success?
  status == 0
end