Class: CFRuntime::Mysql2Client
- Inherits:
-
Object
- Object
- CFRuntime::Mysql2Client
- Defined in:
- lib/cf-runtime/mysql.rb
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Creates and returns a Mysql2
Client
instance connected to a single mysql service. -
.create_from_svc(service_name, options = {}) ⇒ Object
Creates and returns a Mysql2
Client
instance connected to a mysql service with the specified name. -
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified mysql service.
Class Method Details
.create(options = {}) ⇒ Object
Creates and returns a Mysql2 Client
instance connected to a single mysql service. Passes optional Hash of non-connection-related options to Mysql2::Client.new
. Raises ArgumentError
If zero or multiple mysql services are found.
9 10 11 12 13 14 15 16 17 |
# File 'lib/cf-runtime/mysql.rb', line 9 def self.create(={}) service_names = CloudApp.service_names_of_type('mysql') if service_names.length != 1 raise ArgumentError.new("Expected 1 service of mysql type, " + "but found #{service_names.length}. " + "Consider using create_from_svc(service_name) instead.") end create_from_svc(service_names[0],) end |
.create_from_svc(service_name, options = {}) ⇒ Object
Creates and returns a Mysql2 Client
instance connected to a mysql service with the specified name. Passes optional Hash of non-connection-related options to Mysql2::Client.new
. Raises ArgumentError
If specified mysql service is not found.
23 24 25 |
# File 'lib/cf-runtime/mysql.rb', line 23 def self.create_from_svc(service_name, ={}) Mysql2::Client.new((service_name,)) end |
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified mysql service. Returns merged Hash containing (:username, :password, :database, :host, :port). Raises ArgumentError
If specified mysql service is not found.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cf-runtime/mysql.rb', line 30 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] [:username] = service_props[:username] [:password] = service_props[:password] [:database] = service_props[:database] end |