Class: Config::Sources::YAMLSource

Inherits:
Object
  • Object
show all
Defined in:
lib/caco/settings_loader_monkeypatch.rb

Instance Method Summary collapse

Instance Method Details

#decrypt_content(content) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/caco/settings_loader_monkeypatch.rb', line 21

def decrypt_content(content)
  parsed_content = Caco.config.eyaml_parser.parse(content)
  parsed_content.each do |parsed|
    content.sub!(parsed.match, parsed.to_plain_text)
  end
  content
end

#loadObject



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

def load
  result = nil

  if @path and File.exist?(@path)
    content = IO.read(@path)
    descrypted_content = decrypt_content(content)
    result = YAML.load(ERB.new(descrypted_content).result)
  end

  result || {}

  rescue Psych::SyntaxError => e
    raise "YAML syntax error occurred while parsing #{@path}. " \
          "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
          "Error: #{e.message}"
end