Class: RailsDbConfigResolver::DatabaseConfig
- Inherits:
-
Object
- Object
- RailsDbConfigResolver::DatabaseConfig
- Defined in:
- lib/rails_db_config_resolver/database_config.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DatabaseConfig
constructor
A new instance of DatabaseConfig.
- #merge(other) ⇒ Object
- #to_hash ⇒ Object
- #to_url ⇒ Object
Constructor Details
#initialize ⇒ DatabaseConfig
Returns a new instance of DatabaseConfig.
30 31 32 33 34 |
# File 'lib/rails_db_config_resolver/database_config.rb', line 30 def initialize(*) super @pool = cast_to_integer_or_nil(@pool) end |
Class Method Details
.from_url(url_string) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails_db_config_resolver/database_config.rb', line 9 def self.from_url(url_string) url = URI.parse(url_string) pool = (url.query.match(/pool=(\d+)/)[1] if url.query) database = url.path[1..-1] new( adapter: url.scheme, host: url.host, port: url.port, username: url.user, password: url.password, database: database, pool: pool ) end |
Instance Method Details
#merge(other) ⇒ Object
52 53 54 55 56 |
# File 'lib/rails_db_config_resolver/database_config.rb', line 52 def merge(other) my_hash = to_hash other_hash = other.to_hash.reject { |_, value| value.nil? } self.class.from_hash(my_hash.merge(other_hash)) end |
#to_hash ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_db_config_resolver/database_config.rb', line 36 def to_hash { adapter: @adapter, host: @host, port: @port, username: @username, password: @password, database: @database, pool: @pool } end |
#to_url ⇒ Object
48 49 50 |
# File 'lib/rails_db_config_resolver/database_config.rb', line 48 def to_url URI::Generic.build(build_url_hash).to_s end |