Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERB support in configuration files #15

Merged
merged 1 commit into from May 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/danthes.rb
Expand Up @@ -35,7 +35,7 @@ def startup

# Loads the configuration from a given YAML file
def load_config(filename)
yaml = ::YAML.load_file(filename)[env]
yaml = ::YAML.load(ERB.new(File.read(filename)).result)[env]
raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil?
(yaml.keys - ACCEPTED_KEYS).each {|k| yaml.delete(k)}
yaml.each {|k, v| config[k.to_sym] = v}
Expand Down
7 changes: 7 additions & 0 deletions spec/danthes_spec.rb
Expand Up @@ -30,6 +30,13 @@
config[:adapter].should eq('thin')
end

it "loads configuration file with erb via load_config" do
ENV['DANTHES_SERVER'] = "http://example.com"
Danthes.env = 'production'
Danthes.load_config("spec/fixtures/danthes_with_erb.yml")
config[:server].should eq("http://example.com")
end

context "when redis config exists" do
before do
Danthes.env = 'test'
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/danthes_with_erb.yml
@@ -0,0 +1,10 @@
development:
adapter: thin
server: http://dev.local:9292/faye
secret_token: DEVELOPMENT_SECRET_TOKEN
signature_expiration: 600
production:
adapter: thin
server: <%= ENV['DANTHES_SERVER'] %>
secret_token: PRODUCTION_SECRET_TOKEN
signature_expiration: 600