Module: Alf::Sequel::Connection::ConnectionMethods
- Included in:
- Alf::Sequel::Connection
- Defined in:
- lib/alf/sequel/connection/connection_methods.rb
Instance Method Summary collapse
- #close ⇒ Object
- #close! ⇒ Object
- #connection_uri(with_password = false) ⇒ Object
- #ping ⇒ Object
-
#sequel_db ⇒ Object
Yields a Sequel::Database object.
- #with_sequel_db {|sequel_db| ... } ⇒ Object
Instance Method Details
#close ⇒ Object
27 28 29 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 27 def close @sequel_db.disconnect if @sequel_db && @sequel_db != conn_spec end |
#close! ⇒ Object
31 32 33 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 31 def close! @sequel_db.disconnect if @sequel_db end |
#connection_uri(with_password = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 6 def connection_uri(with_password = false) if conn_spec.is_a?(Hash) cs = Tuple(self.conn_spec) adapter, host, port, database, user, password = cs.values_at(:adapter, :host, :port, :database, :user, :password) user = "#{user}:#{password}" if user and password and with_password user = "#{user}@" if user host = "localhost" if host.nil? and not(adapter =~ /sqlite/) host = "#{host}:#{port}" if host and port host = "/#{user}#{host}" if host or user "#{adapter}:/#{host}/#{database}" elsif conn_spec.is_a?(String) conn_spec else "Alf::Sequel::Connection(#{conn_spec})" end end |
#ping ⇒ Object
23 24 25 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 23 def ping sequel_db.test_connection end |
#sequel_db ⇒ Object
Yields a Sequel::Database object
40 41 42 43 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 40 def sequel_db @sequel_db ||= Adapter.sequel_db(conn_spec) block_given? ? yield(@sequel_db) : @sequel_db end |
#with_sequel_db {|sequel_db| ... } ⇒ Object
35 36 37 |
# File 'lib/alf/sequel/connection/connection_methods.rb', line 35 def with_sequel_db yield(sequel_db) end |