Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/settingslogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def initialize(hash_or_file = self.class.source, section = nil)
self.replace hash_or_file
else
file_contents = open(hash_or_file).read
hash = file_contents.empty? ? {} : YAML.load(ERB.new(file_contents).result).to_hash
hash = file_contents.empty? ? {} : parse_yaml_content(file_contents)
if self.class.namespace
hash = hash[self.class.namespace] or return missing_key("Missing setting '#{self.class.namespace}' in #{hash_or_file}")
end
Expand Down Expand Up @@ -188,4 +188,12 @@ def missing_key(msg)

raise MissingSetting, msg
end

private

def parse_yaml_content(file_content)
YAML.load(ERB.new(file_content).result, aliases: true).to_hash
rescue ArgumentError
YAML.load(ERB.new(file_content).result).to_hash
end
end
9 changes: 8 additions & 1 deletion spec/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ language:
haskell:
paradigm: functional
smalltalk:
paradigm: object oriented
paradigm: object oriented

collides:
does: not
Expand All @@ -26,3 +26,10 @@ array:
name: first
-
name: second

alias: &default
example:
key: value

uses_default_alias:
<<: *default