Module: Ronin::DB::ConfigFile Private
- Defined in:
- lib/ronin/db/config_file.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Represents the ~/.config/ronin-db/databases.yml
configuration file.
Constant Summary collapse
- PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path to the
~/.config/ronin-db/databases.yml
configuration file. File.join(DB::Home::CONFIG_DIR,'databases.yml')
- DEFAULT_DB_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path to the default sqlite3 database file (
~/.local/share/ronin-db/default.sqlite3
). File.join(DB::Home::LOCAL_SHARE_DIR,'default.sqlite3')
- DEFAULT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default database configuration.
{ default: { adapter: 'sqlite3', database: DEFAULT_DB_FILE } }
Class Method Summary collapse
-
.edit(path = PATH) {|yaml| ... } ⇒ Object
private
Opens the configuration file and edits it's contents.
-
.load(path = PATH) ⇒ Hash{Symbol => Hash}
private
Loads configuration data from the given path.
-
.validate(path, data) ⇒ true
private
Validates the loaded configuration data from the given path.
Class Method Details
.edit(path = PATH) {|yaml| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Opens the configuration file and edits it's contents.
127 128 129 130 131 132 133 134 135 |
# File 'lib/ronin/db/config_file.rb', line 127 def self.edit(path=PATH,&block) unless File.file?(path) # create the parent directory for YAML::Store FileUtils.mkdir_p(File.dirname(path)) end store = YAML::Store.new(path) store.transaction(&block) end |
.load(path = PATH) ⇒ Hash{Symbol => Hash}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loads configuration data from the given path.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ronin/db/config_file.rb', line 104 def self.load(path=PATH) if File.file?(path) config = YAML.load_file(path, symbolize_names: true).tap do |data| validate(path,data) end DEFAULT_CONFIG.merge(config) else DEFAULT_CONFIG end end |
.validate(path, data) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates the loaded configuration data from the given path.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ronin/db/config_file.rb', line 67 def self.validate(path,data) unless data.kind_of?(Hash) raise(InvalidConfig,"config data must be a Hash: #{data.inspect}") end data.each do |key,value| unless key.kind_of?(Symbol) raise(InvalidConfig,"all Hash keys must be a Symbol: #{key.inspect}") end unless value.kind_of?(Hash) raise(InvalidConfig,"all Hash values must also be a Hash: #{value.inspect}") end value.each_key do |sub_key| unless sub_key.kind_of?(Symbol) raise(InvalidConfig,"all sub-keys must be a Symbol: #{sub_key.inspect}") end end end return true end |