Class: SequelRails3::Configuration
- Inherits:
-
Hash
- Object
- Hash
- SequelRails3::Configuration
- Defined in:
- lib/sequel_rails3/configuration.rb
Instance Method Summary collapse
-
#initialize(app) ⇒ Configuration
constructor
A new instance of Configuration.
- #normalize! ⇒ Object
Constructor Details
#initialize(app) ⇒ Configuration
Returns a new instance of Configuration.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/sequel_rails3/configuration.rb', line 3 def initialize(app) super config = app.config.database_configuration unless config && config[Rails.env] raise ArgumentError, "no database configured for environment #{Rails.env}" end replace(config[Rails.env]) end |
Instance Method Details
#normalize! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sequel_rails3/configuration.rb', line 14 def normalize! symbolize_keys! each_pair do |k, v| case k when :uri self[:url] = delete(:uri) when :adapter case v.to_sym when :sqlite3 self[k] = :sqlite when :postgresql self[k] = :postgres end end end # always use jdbc when running jruby if defined?(JRUBY_VERSION) if self[:adapter] case self[:adapter].to_sym when :postgres self[:adapter] = :postgresql end self[:adapter] = "jdbc:#{self[:adapter]}" end end # some adapters only support an url if self[:adapter] && self[:adapter] =~ /^(jdbc|do):/ params = {} each_pair do |k, v| next if [:adapter, :host, :port, :database].include?(k) params[k] = v end params_str = params.each_pair{ |k, v| "#{k}=#{v}" } port = self[:port] ? ":#{self[:port]}" : "" self[:url] = "%s://%s%s/%s?%s" % [self[:adapter], self[:host], port, self[:database], params_str] end end |