Class: SwitchDb::Configuration
- Inherits:
-
Object
- Object
- SwitchDb::Configuration
- Defined in:
- lib/switch_db/configuration.rb
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#password ⇒ Object
Returns the value of attribute password.
-
#reference_set_file ⇒ Object
Returns the value of attribute reference_set_file.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Instance Method Summary collapse
- #configuration_keys ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #reference_set_file_full_path ⇒ Object
- #to_h ⇒ Object
- #write_configuration_file ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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.('~/.cache/switch_db')) @user_name = 'root' @password = nil load_from_config_file(configuration_full_path) end |
Instance Attribute Details
#cache_dir ⇒ Object (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_file ⇒ Object (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 |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/switch_db/configuration.rb', line 10 def password @password end |
#reference_set_file ⇒ Object
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_name ⇒ Object
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_keys ⇒ Object
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_path ⇒ Object
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_h ⇒ Object
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_file ⇒ Object
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 |