Class: PGPool::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pgpool/response.rb

Overview

class: Response

Constant Summary collapse

OK =
0
UNKNOWN =

Unknown Error (should not occur)

1
EOF =

EOF Error

2
NOMEM =

Memory shortage

3
READ =

Error while reading from the server

4
WRITE =

Error while writing to the server

5
TIMEOUT =

Timeout

6
INVAL =

Argument(s) to the PCP command was invalid

7
CONN =

Server connection error

8
NOCONN =

No connection exists

9
SOCK =

Socket error

10
HOST =

Hostname resolution error

11
BACKEND =

PCP process error on the server

12
AUTH =

Authorization failure

13
ERROR_MESSAGES =
{
  OK:      'No error',
  UNKNOWN: 'Unknown Error',
  EOF:     'EOF Error',
  NOMEM:   'Memory shortage',
  READ:    'Error while reading from the server',
  WRITE:   'Error while writing to the server',
  TIMEOUT: 'Timeout',
  INVAL:   'Argument(s) to the PCP command was invalid',
  CONN:    'Server connection error',
  NOCONN:  'No connection exists',
  SOCK:    'Socket error',
  HOST:    'Hostname resolution error',
  BACKEND: 'PCP process error on the server',
  AUTH:    'Authorization failure'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_id, command) ⇒ Response

Returns a new instance of Response.



41
42
43
44
45
46
# File 'lib/pgpool/response.rb', line 41

def initialize(node_id, command)
  @status    = command.exitstatus
  @node_info = success? ? NodeInfo.build_from_raw_data(node_id, command.stdout) : command.stderr

  self
end

Instance Attribute Details

#node_infoObject (readonly)

Returns the value of attribute node_info.



39
40
41
# File 'lib/pgpool/response.rb', line 39

def node_info
  @node_info
end

#statusObject (readonly)

Returns the value of attribute status.



39
40
41
# File 'lib/pgpool/response.rb', line 39

def status
  @status
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pgpool/response.rb', line 52

def error?
  status != OK
end

#error_messageObject



56
57
58
# File 'lib/pgpool/response.rb', line 56

def error_message
  ERROR_MESSAGES[@status]
end

#inspectObject



64
65
66
# File 'lib/pgpool/response.rb', line 64

def inspect
  to_hash.inspect
end

#success?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pgpool/response.rb', line 48

def success?
  status == OK
end

#to_hashObject



60
61
62
# File 'lib/pgpool/response.rb', line 60

def to_hash
  { status: @status, node_info: @node_info }
end

#to_sObject



68
69
70
# File 'lib/pgpool/response.rb', line 68

def to_s
  "#{inspect}"
end