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.



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

def initialize
  @config_file = 'config.yml'
  @reference_set_file = 'reference_set.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.



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

def password
  @password
end

#reference_set_fileObject

Returns the value of attribute reference_set_file.



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

def reference_set_file
  @reference_set_file
end

#user_nameObject

Returns the value of attribute user_name.



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

def user_name
  @user_name
end

Instance Method Details

#configuration_keysObject



39
40
41
42
43
44
45
# File 'lib/switch_db/configuration.rb', line 39

def configuration_keys
  i[
    reference_set_file
    user_name
    password
  ]
end

#reference_set_file_full_pathObject



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

def reference_set_file_full_path
  cache_dir.join(reference_set_file)
end

#to_hObject



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

def to_h
  {
    reference_set_file: reference_set_file,
    user_name: user_name,
    password: password
  }
end

#write_configuration_fileObject



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

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