Class: SwitchDb::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/switch_db/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
# File 'lib/switch_db/configuration.rb', line 11

def initialize
  @config_file = 'config.yml'
  @cache_dir = Pathname.new(File.expand_path('~/.cache/switch_db'))
  @user_name = 'root'
  @password = nil

  load_from_config_file(configuration_full_path)
end

Instance Attribute Details

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



7
8
9
# File 'lib/switch_db/configuration.rb', line 7

def cache_dir
  @cache_dir
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



6
7
8
# File 'lib/switch_db/configuration.rb', line 6

def config_file
  @config_file
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/switch_db/configuration.rb', line 9

def password
  @password
end

#user_nameObject

Returns the value of attribute user_name.



8
9
10
# File 'lib/switch_db/configuration.rb', line 8

def user_name
  @user_name
end

Instance Method Details

#configuration_keysObject



32
33
34
35
36
37
# File 'lib/switch_db/configuration.rb', line 32

def configuration_keys
  %i[
    user_name
    password
  ]
end

#to_hObject



20
21
22
23
24
25
# File 'lib/switch_db/configuration.rb', line 20

def to_h
  {
    user_name: user_name,
    password: password
  }.delete_if { |_, value| value.nil? || value.empty? }
end

#write_configuration_fileObject



27
28
29
30
# File 'lib/switch_db/configuration.rb', line 27

def write_configuration_file
  FileUtils.mkdir_p(File.dirname(configuration_full_path))
  File.write(configuration_full_path, to_h.to_yaml)
end