Class: ODBCAdapter::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/odbc_adapter/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



5
6
7
8
9
10
# File 'lib/odbc_adapter/registry.rb', line 5

def initialize
  @dbs = {
    /my.*sql/i  => :MySQL,
    /postgres/i => :PostgreSQL
  }
end

Instance Attribute Details

#dbsObject (readonly)

Returns the value of attribute dbs.



3
4
5
# File 'lib/odbc_adapter/registry.rb', line 3

def dbs
  @dbs
end

Instance Method Details

#adapter_for(reported_name) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/odbc_adapter/registry.rb', line 12

def adapter_for(reported_name)
  reported_name = reported_name.downcase.gsub(/\s/, '')
  found =
    dbs.detect do |pattern, adapter|
      adapter if reported_name =~ pattern
    end

  normalize_adapter(found && found.last || :Null)
end

#register(pattern, superclass = Object, &block) ⇒ Object



22
23
24
# File 'lib/odbc_adapter/registry.rb', line 22

def register(pattern, superclass = Object, &block)
  dbs[pattern] = Class.new(superclass, &block)
end