Class: ManageIQ::PostgresHaAdmin::RailsConfigHandler
- Inherits:
-
ConfigHandler
- Object
- ConfigHandler
- ManageIQ::PostgresHaAdmin::RailsConfigHandler
- Defined in:
- lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RailsConfigHandler
constructor
A new instance of RailsConfigHandler.
- #name ⇒ Object
- #read ⇒ Object
- #write(params) ⇒ Object
Methods inherited from ConfigHandler
#after_failover, #before_failover, #do_after_failover, #do_before_failover
Constructor Details
#initialize(options = {}) ⇒ RailsConfigHandler
Returns a new instance of RailsConfigHandler.
10 11 12 13 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 10 def initialize( = {}) @file_path = [:file_path] @environment = [:environment] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 8 def environment @environment end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 8 def file_path @file_path end |
Instance Method Details
#name ⇒ Object
15 16 17 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 15 def name "Rails #{environment} Config Handler" end |
#read ⇒ Object
19 20 21 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 19 def read rails_params_to_pg(YAML.load_file(file_path)[environment]) end |
#write(params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 23 def write(params) db_yml = YAML.load_file(file_path) db_yml[environment].merge!(pg_parameters_to_rails(params)) remove_empty(db_yml[environment]) new_name = "#{file_path}_#{Time.current.strftime("%d-%B-%Y_%H.%M.%S")}" FileUtils.copy(file_path, new_name) begin File.write(file_path, db_yml.to_yaml) rescue FileUtils.mv(new_name, file_path) raise end new_name end |