Class: CFRuntime::PGClient
- Inherits:
-
Object
- Object
- CFRuntime::PGClient
- Defined in:
- lib/cf-runtime/postgres.rb
Class Method Summary collapse
-
.create(options = {}) {|cfoptions| ... } ⇒ Object
Creates and returns a
PGconn
connecting to a single postgresql service. -
.create_from_svc(service_name, options = {}) {|cfoptions| ... } ⇒ Object
Creates and returns a
PGconn
connecting to a postgresql service with the specified name. -
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified postgresql service.
Class Method Details
.create(options = {}) {|cfoptions| ... } ⇒ Object
Creates and returns a PGconn
connecting to a single postgresql service. Passes optional Hash of non-connection-related options to PGconn.open
. Raises ArgumentError
If zero or multiple postgresql services are found.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cf-runtime/postgres.rb', line 9 def self.create(={}) service_names = CloudApp.service_names_of_type('postgresql') if service_names.length != 1 raise ArgumentError.new("Expected 1 service of postgresql type, " + "but found #{service_names.length}. " + "Consider using create_from_svc(service_name) instead.") end = (service_names[0],) #Pass back the options for verification yield if block_given? PGconn.open() end |
.create_from_svc(service_name, options = {}) {|cfoptions| ... } ⇒ Object
Creates and returns a PGconn
connecting to a postgresql service with the specified name. Passes optional Hash of non-connection-related options to PGconn.open
. Raises ArgumentError
If specified postgresql service is not found.
26 27 28 29 30 31 |
# File 'lib/cf-runtime/postgres.rb', line 26 def self.create_from_svc(service_name,={}) = (service_name,) #Pass back the options for verification yield if block_given? PGconn.open() end |
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified postgresql service. Returns merged Hash containing (:user, :password, :dbname, :host, :port). Raises ArgumentError
If specified postgresql service is not found.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cf-runtime/postgres.rb', line 36 def self.(service_name,={}) service_props = CFRuntime::CloudApp.service_props(service_name) if service_props.nil? raise ArgumentError.new("Service with name #{service_name} not found") end = [:host] = service_props[:host] [:port] = service_props[:port] [:user] = service_props[:username] [:password] = service_props[:password] [:dbname] = service_props[:database] end |