Class: DbSchema::Configuration
- Inherits:
-
Object
- Object
- DbSchema::Configuration
- Defined in:
- lib/db_schema/configuration.rb
Constant Summary collapse
- DEFAULT_PARAMS =
{ adapter: 'postgres', host: 'localhost', port: 5432, database: nil, user: nil, password: '', log_changes: true, dry_run: false, post_check: true }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #dry_run? ⇒ Boolean
-
#initialize(params = DEFAULT_PARAMS) ⇒ Configuration
constructor
A new instance of Configuration.
- #log_changes? ⇒ Boolean
- #merge(new_params) ⇒ Object
- #post_check_enabled? ⇒ Boolean
Constructor Details
#initialize(params = DEFAULT_PARAMS) ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 |
# File 'lib/db_schema/configuration.rb', line 19 def initialize(params = DEFAULT_PARAMS) @params = params end |
Class Method Details
.params_from_url(url_string) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/db_schema/configuration.rb', line 52 def params_from_url(url_string) return {} if url_string.nil? url = URI.parse(url_string) Utils.remove_nil_values( adapter: url.scheme, host: url.host, port: url.port, database: url.path.sub(/\A\//, ''), user: url.user, password: url.password ) end |
Instance Method Details
#dry_run? ⇒ Boolean
43 44 45 |
# File 'lib/db_schema/configuration.rb', line 43 def dry_run? @params[:dry_run] end |
#log_changes? ⇒ Boolean
39 40 41 |
# File 'lib/db_schema/configuration.rb', line 39 def log_changes? @params[:log_changes] end |
#merge(new_params) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/db_schema/configuration.rb', line 23 def merge(new_params) params = [ @params, Configuration.params_from_url(new_params[:url]), Utils.filter_by_keys(new_params, *DEFAULT_PARAMS.keys) ].reduce(:merge) Configuration.new(params) end |
#post_check_enabled? ⇒ Boolean
47 48 49 |
# File 'lib/db_schema/configuration.rb', line 47 def post_check_enabled? @params[:post_check] end |