Class: SequelRails::DbConfig

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/sequel_rails/db_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw, opts = {}) ⇒ DbConfig

Returns a new instance of DbConfig.



6
7
8
9
10
11
12
# File 'lib/sequel_rails/db_config.rb', line 6

def initialize(raw, opts = {})
  merge! raw
  self[:port] = port.to_i if include? :port
  normalize_adapter if include? :adapter
  normalize_db opts[:root] if include? :database
  self[:max_connections] = pool if include? :pool
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *a) ⇒ Object

allow easier access



15
16
17
18
# File 'lib/sequel_rails/db_config.rb', line 15

def method_missing(key, *a)
  return self[key] if a.empty? && include?(key)
  super
end

Instance Method Details

#respond_to_missing?(key, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sequel_rails/db_config.rb', line 20

def respond_to_missing?(key, include_private = false)
  include?(key) || super
end

#urlObject



24
25
26
27
28
29
# File 'lib/sequel_rails/db_config.rb', line 24

def url
  # the gsub transforms foo:/bar
  # (which jdbc doesn't like)
  # into foo:///bar
  self[:url] || make_url.to_s.gsub(%r{:/(?=\w)}, ':///')
end