Class: MongoDbUtils::ConfigLoader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject (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

#flushObject



21
22
23
24
25
26
# File 'lib/mongo-db-utils/config-loader.rb', line 21

def flush
  path = File.expand_path(@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.expand_path(@config_path), 'w' ) do |out|
    YAML.dump( config, out )
  end
end