Class: Provider::CDB_FILESYSTEM

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

Instance Method Summary collapse

Instance Method Details

#load_yaml(filename) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/depengine/provider/cdb_filesystem.rb', line 4

def load_yaml(filename)
  if File.file? filename
      begin
        YAML::load_file(filename)
      rescue StringIndexOutOfBoundsException => e
        puts "Error: YAML parsing in #{filename}"
        raise "YAML not parsable"
        false
      rescue Exception => e
        puts "Error: YAML parsing in #{filename}"
        raise "YAML not parsable"
        false
      end
  else
    raise "File not found: #{filename}"
  end
end

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/depengine/provider/cdb_filesystem.rb', line 22

def read_data(cdb_path, options={})
  config    = Hash.new
  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)
    if additional_config.is_a?(Hash)
      if options[:disable_merge]
        config = additional_config
      else
        config.merge!( additional_config )
      end
    end
  end
  config.to_json
end