Skip to content

Commit

Permalink
accepting ERB interpolation into YAML config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Wellington Santos committed Apr 4, 2014
1 parent fcc769e commit 8002497
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/daemon_kit/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def load( config )

raise ArgumentError, "Can't find #{path}" unless File.exists?( path )

new( YAML.load_file( path ) )
config_content = ERB.new(File.read(path)).result(binding)

new( YAML.load( config_content ) )
end

# Return the +config+.yml file as a raw hash.
Expand Down
8 changes: 8 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
FileUtils.mkdir_p( DAEMON_ROOT + "/config" )
FileUtils.cp( File.dirname(__FILE__) + '/fixtures/env.yml', DAEMON_ROOT + '/config/' )
FileUtils.cp( File.dirname(__FILE__) + '/fixtures/noenv.yml', DAEMON_ROOT + '/config/' )
FileUtils.cp( File.dirname(__FILE__) + '/fixtures/erb.yml', DAEMON_ROOT + '/config/' )
end

it "should render ERB interpolation before loading config" do
ENV.should_receive(:[]).with("foo").and_return("bar")
config = DaemonKit::Config.load('erb')

config.string.should == 'bar'
end

it "should parse env keys correctly" do
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/erb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test ENV keys

defaults: &defaults
string: <%= ENV["foo"] %>
array:
- entry
- entry

development:
test: no!
<<: *defaults

test:
test: yes!
<<: *defaults

0 comments on commit 8002497

Please sign in to comment.