class Pakyow::Data::Connection
Attributes
adapter[R]
failure[R]
name[R]
opts[R]
type[R]
Public Class Methods
adapter(type)
click to toggle source
# File lib/pakyow/data/connection.rb, line 92 def adapter(type) if @adapter_types.include?(type.to_sym) require "pakyow/data/adapters/#{type}" Adapters.const_get(Support.inflector.camelize(type)) else raise UnknownAdapter.new_with_message(type: type) end end
new(type:, name:, string: nil, opts: nil, logger: nil)
click to toggle source
# File lib/pakyow/data/connection.rb, line 22 def initialize(type:, name:, string: nil, opts: nil, logger: nil) @type, @name, @logger, @failure = type, name, logger, nil @opts = self.class.adapter(type).build_opts( opts.is_a?(Hash) ? opts : self.class.parse_connection_string(string) ) @adapter = self.class.adapter(@type).new(@opts, logger: @logger) rescue ConnectionError, MissingAdapter => error error.context = self @failure = error end
parse_connection_string(connection_string)
click to toggle source
# File lib/pakyow/data/connection.rb, line 73 def parse_connection_string(connection_string) uri = URI(connection_string) { adapter: uri.scheme, path: uri.path, host: uri.host, port: uri.port, user: uri.user, password: uri.password }.merge( CGI::parse(uri.query.to_s).transform_values(&:first).indifferentize ) end
register_adapter(type)
click to toggle source
# File lib/pakyow/data/connection.rb, line 88 def register_adapter(type) (@adapter_types << type).uniq! end
Public Instance Methods
auto_migrate?()
click to toggle source
# File lib/pakyow/data/connection.rb, line 43 def auto_migrate? migratable? && @adapter.auto_migratable? end
connect()
click to toggle source
# File lib/pakyow/data/connection.rb, line 51 def connect @adapter.connect end
connected?()
click to toggle source
# File lib/pakyow/data/connection.rb, line 35 def connected? !failed? && @adapter.connected? end
disconnect()
click to toggle source
# File lib/pakyow/data/connection.rb, line 55 def disconnect @adapter.disconnect end
failed?()
click to toggle source
# File lib/pakyow/data/connection.rb, line 39 def failed? !@failure.nil? end
migratable?()
click to toggle source
# File lib/pakyow/data/connection.rb, line 47 def migratable? connected? && @adapter.migratable? end
types()
click to toggle source
# File lib/pakyow/data/connection.rb, line 59 def types if @adapter.class.const_defined?("TYPES") @adapter.class.types_for_adapter(adapter.connection.opts[:adapter]) else {} end end