Class: Provider::CdbFilesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/provider/cdb_filesystem.rb

Instance Method Summary collapse

Instance Method Details

#load_yaml(filename) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/depengine/provider/cdb_filesystem.rb', line 3

def load_yaml(filename)
  if File.file? filename
    begin
      YAML.load_file(filename)
    rescue
      puts "Error: YAML parsing in #{filename}"
      raise 'YAML not parsable'
    end
  else
    fail "File not found: #{filename}"
  end
end

#read_data(cdb_path, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/depengine/provider/cdb_filesystem.rb', line 16

def read_data(cdb_path, options = {})
  config    = {}
  basedir   = File.join(($recipe_config[:recipe_base_dir] || $recipe_config[:deploy_home]), 'cdb')
  filename  = ''
  if cdb_path.nil? or cdb_path.empty?
    $log.writer.error 'Error while talking to configuration database, no cdb path given!'
    exit 1
  end
  paths = cdb_path.split('/')

  paths.each do |path|
    basedir = File.join(basedir, path.to_s)
    filename = basedir + '.yaml'
    additional_config = load_yaml(filename)
    next unless additional_config.is_a?(Hash)
    if options[:disable_merge]
      config = additional_config
    else
      config.merge!(additional_config)
    end
  end
  config.to_json
end