class SwitchDb::Configuration
Attributes
cache_dir[R]
config_file[R]
password[RW]
reference_set_file[RW]
user_name[RW]
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
configuration_keys()
click to toggle source
# File lib/switch_db/configuration.rb, line 39 def configuration_keys %i[ reference_set_file user_name password ] end
reference_set_file_full_path()
click to toggle source
# File lib/switch_db/configuration.rb, line 22 def reference_set_file_full_path cache_dir.join(reference_set_file) end
to_h()
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
configuration_full_path()
click to toggle source
# File lib/switch_db/configuration.rb, line 49 def configuration_full_path cache_dir.join(config_file) end
load_from_config_file(path)
click to toggle source
# File lib/switch_db/configuration.rb, line 53 def load_from_config_file(path) yaml = YAML.load_file(path) yaml.each do |key, value| case key when 'cache_dir' @cache_dir = Pathname.new(File.expand_path(cache_dir)) else public_send("#{key}=", value) if respond_to?("#{key}=") end end rescue Errno::ENOENT # Do nothing end