Class: MongoDbUtils::ConfigLoader
- Inherits:
-
Object
- Object
- MongoDbUtils::ConfigLoader
- Defined in:
- lib/mongo-db-utils/config-loader.rb
Constant Summary collapse
- ROOT_FOLDER =
File.join("~",".mongo-db-utils")
- CONFIG_LOCATION =
File.join(ROOT_FOLDER, "config.yml")
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(config_path) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #save(config) ⇒ Object
Constructor Details
#initialize(config_path) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
16 17 18 19 |
# File 'lib/mongo-db-utils/config-loader.rb', line 16 def initialize(config_path) @config_path = config_path load end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/mongo-db-utils/config-loader.rb', line 14 def config @config end |
Instance Method Details
#flush ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mongo-db-utils/config-loader.rb', line 21 def flush path = File.(@config_path) puts "removing: #{path}" FileUtils.rm(path) if File.exist?(path) initialize_files(path) end |
#save(config) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/mongo-db-utils/config-loader.rb', line 28 def save(config) raise "config is nil" if config.nil? File.open( File.(@config_path), 'w' ) do |out| YAML.dump( config, out ) end end |