Class: ManageIQ::PostgresHaAdmin::DatabaseYml
- Inherits:
-
Object
- Object
- ManageIQ::PostgresHaAdmin::DatabaseYml
- Defined in:
- lib/manageiq/postgres_ha_admin/database_yml.rb
Instance Attribute Summary collapse
-
#db_yml_file ⇒ Object
readonly
Returns the value of attribute db_yml_file.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
-
#initialize(db_yml_file, environment) ⇒ DatabaseYml
constructor
A new instance of DatabaseYml.
- #pg_params_from_database_yml ⇒ Object
- #update_database_yml(params) ⇒ Object
Constructor Details
#initialize(db_yml_file, environment) ⇒ DatabaseYml
10 11 12 13 |
# File 'lib/manageiq/postgres_ha_admin/database_yml.rb', line 10 def initialize(db_yml_file, environment) @db_yml_file = db_yml_file @environment = environment end |
Instance Attribute Details
#db_yml_file ⇒ Object (readonly)
Returns the value of attribute db_yml_file.
8 9 10 |
# File 'lib/manageiq/postgres_ha_admin/database_yml.rb', line 8 def db_yml_file @db_yml_file end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/manageiq/postgres_ha_admin/database_yml.rb', line 8 def environment @environment end |
Instance Method Details
#pg_params_from_database_yml ⇒ Object
15 16 17 |
# File 'lib/manageiq/postgres_ha_admin/database_yml.rb', line 15 def pg_params_from_database_yml rails_params_to_pg(YAML.load_file(db_yml_file)[environment]) end |
#update_database_yml(params) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/manageiq/postgres_ha_admin/database_yml.rb', line 19 def update_database_yml(params) db_yml = YAML.load_file(db_yml_file) db_yml[environment].merge!(pg_parameters_to_rails(params)) remove_empty(db_yml[environment]) new_name = "#{db_yml_file}_#{Time.current.strftime("%d-%B-%Y_%H.%M.%S")}" FileUtils.copy(db_yml_file, new_name) begin File.write(db_yml_file, db_yml.to_yaml) rescue FileUtils.mv(new_name, db_yml_file) raise end new_name end |