Class: ManageIQ::PostgresHaAdmin::RailsConfigHandler

Inherits:
ConfigHandler
  • Object
show all
Defined in:
lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @file_path   = options[:file_path]
  @environment = options[:environment]
end

Instance Attribute Details

#environmentObject (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_pathObject (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

#nameObject



15
16
17
# File 'lib/manageiq/postgres_ha_admin/config_handler/rails_config_handler.rb', line 15

def name
  "Rails #{environment} Config Handler"
end

#readObject



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