Permalink
Browse files

accepting ERB interpolation into YAML config files

  • Loading branch information...
1 parent fcc769e commit 8002497da66b41e196860f4b794d984cf63ec035 Wellington Santos committed Apr 4, 2014
Showing with 26 additions and 1 deletion.
  1. +3 −1 lib/daemon_kit/config.rb
  2. +8 −0 spec/config_spec.rb
  3. +15 −0 spec/fixtures/erb.yml
@@ -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.
View
@@ -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
View
@@ -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.