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.
-
#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.
- #to_h ⇒ Object
- #write_configuration_file ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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.('~/.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.
9 10 11 |
# File 'lib/switch_db/configuration.rb', line 9 def password @password end |
#user_name ⇒ Object
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_keys ⇒ Object
32 33 34 35 36 37 |
# File 'lib/switch_db/configuration.rb', line 32 def configuration_keys %i[ user_name password ] end |
#to_h ⇒ Object
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_file ⇒ Object
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 |