Class: CelluloidIOPGListener::Initialization::ClientExtractedSignature

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb

Overview

Null Object Pattern, just in case there are no options passed to initialize

Options must be the same named parameters that PG.connect() expects in its argument hash
The other parameter formats are accepted by PG::Connection.new are not supported here.
Named after, and structurally identical to, PG::Connection#conninfo_hash

Constant Summary collapse

KEYS =
[:host, :hostaddr, :port, :dbname, :user, :password, :connect_timeout, :options, :tty, :sslmode, :krbsrvname, :gsslib, :service]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ClientExtractedSignature

args - an array



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb', line 25

def initialize(*args)
  hash_arg = args.last.is_a?(Hash) ? args.pop : {}
  # Extract the channel first, as it is required
  @channel = hash_arg.delete(:channel) || raise(ArgumentError, "[#{self.class}] :channel is required, but got #{args} and #{hash_arg}")
  # Extract the args for PG.connect
  @conninfo_hash = (hash_arg.keys & KEYS).
    each_with_object({}) { |k,h| h.update(k => hash_arg.delete(k)) }.
    # Future proof. Provide a way to send in any PG.connect() options not explicitly defined in KEYS
    merge(hash_arg.delete(:conninfo_hash) || {})
  # Add any other named parameters back to the args for super
  args << hash_arg unless hash_arg.empty?
  @super_signature = args
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



22
23
24
# File 'lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb', line 22

def channel
  @channel
end

#conninfo_hashObject (readonly)

Returns the value of attribute conninfo_hash.



21
22
23
# File 'lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb', line 21

def conninfo_hash
  @conninfo_hash
end

#super_signatureObject (readonly)

Returns the value of attribute super_signature.



20
21
22
# File 'lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb', line 20

def super_signature
  @super_signature
end