Class: Hanami::Model::Migrator::Connection Private
- Inherits:
- 
      Object
      
        - Object
- Hanami::Model::Migrator::Connection
 
- Defined in:
- lib/hanami/model/migrator/connection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Sequel connection wrapper
Normalize external adapters interfaces
Instance Method Summary collapse
- 
  
    
      #database  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB name from conenction. 
- 
  
    
      #database_type  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB type. 
- 
  
    
      #global_uri  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB connection wihout specifying database name. 
- 
  
    
      #host  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB connection host. 
- 
  
    
      #initialize(configuration)  ⇒ Connection 
    
    
  
  
  
    constructor
  
  
  
  
  
  private
  
    A new instance of Connection. 
- 
  
    
      #jdbc?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  private
  
    Returns a boolean telling if a DB connection is from JDBC or not. 
- 
  
    
      #parsed_uri  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns database connection URI instance without JDBC namespace. 
- 
  
    
      #password  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns user from DB connection. 
- 
  
    
      #port  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB connection port. 
- #raw ⇒ Object private
- #schema ⇒ Object private
- 
  
    
      #table(name)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Return the database table for the given name. 
- 
  
    
      #uri  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns DB connection URI directly from adapter. 
- 
  
    
      #user  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Returns user from DB connection. 
Constructor Details
#initialize(configuration) ⇒ Connection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Connection.
| 17 18 19 | # File 'lib/hanami/model/migrator/connection.rb', line 17 def initialize(configuration) @configuration = configuration end | 
Instance Method Details
#database ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB name from conenction
Even when adapter doesn’t provide it explicitly it tries to parse
| 60 61 62 | # File 'lib/hanami/model/migrator/connection.rb', line 60 def database @database ||= parsed_uri.path[1..-1] end | 
#database_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB type
| 72 73 74 75 76 77 78 79 80 81 | # File 'lib/hanami/model/migrator/connection.rb', line 72 def database_type case uri when /sqlite/ :sqlite when /postgres/ :postgres when /mysql/ :mysql end end | 
#global_uri ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB connection wihout specifying database name
| 115 116 117 | # File 'lib/hanami/model/migrator/connection.rb', line 115 def global_uri uri.sub(parsed_uri.select(:path).first, "") end | 
#host ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB connection host
Even when adapter doesn’t provide it explicitly it tries to parse
| 40 41 42 | # File 'lib/hanami/model/migrator/connection.rb', line 40 def host @host ||= parsed_uri.host || parsed_opt("host") end | 
#jdbc? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean telling if a DB connection is from JDBC or not
| 123 124 125 | # File 'lib/hanami/model/migrator/connection.rb', line 123 def jdbc? !uri.scan("jdbc:").empty? end | 
#parsed_uri ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns database connection URI instance without JDBC namespace
| 131 132 133 | # File 'lib/hanami/model/migrator/connection.rb', line 131 def parsed_uri @parsed_uri ||= URI.parse(uri.sub("jdbc:", "")) end | 
#password ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns user from DB connection
Even when adapter doesn’t provide it explicitly it tries to parse
| 99 100 101 | # File 'lib/hanami/model/migrator/connection.rb', line 99 def password @password ||= parsed_opt("password") || parsed_uri.password end | 
#port ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB connection port
Even when adapter doesn’t provide it explicitly it tries to parse
| 50 51 52 | # File 'lib/hanami/model/migrator/connection.rb', line 50 def port @port ||= parsed_uri.port || parsed_opt("port").to_i.nonzero? end | 
#raw ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
| 23 24 25 26 27 28 29 30 31 32 | # File 'lib/hanami/model/migrator/connection.rb', line 23 def raw @raw ||= begin Sequel.connect( configuration.url, loggers: [configuration.migrations_logger] ) rescue Sequel::AdapterNotFound raise MigrationError.new("Current adapter (#{configuration.adapter.type}) doesn't support SQL database operations.") end end | 
#schema ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
| 136 137 138 | # File 'lib/hanami/model/migrator/connection.rb', line 136 def schema configuration.schema end | 
#table(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the database table for the given name
| 144 145 146 | # File 'lib/hanami/model/migrator/connection.rb', line 144 def table(name) raw[name] if raw.tables.include?(name) end | 
#uri ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns DB connection URI directly from adapter
| 107 108 109 | # File 'lib/hanami/model/migrator/connection.rb', line 107 def uri @configuration.url end | 
#user ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns user from DB connection
Even when adapter doesn’t provide it explicitly it tries to parse
| 89 90 91 | # File 'lib/hanami/model/migrator/connection.rb', line 89 def user @user ||= parsed_opt("user") || parsed_uri.user end |