Skip to content

Commit

Permalink
Parse ERB code in configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Catteau committed Jun 3, 2014
1 parent c54639f commit 2be15d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/gemnasium/configuration.rb
@@ -1,4 +1,5 @@
require 'yaml'
require 'erb'

module Gemnasium
class Configuration
Expand All @@ -23,7 +24,7 @@ def initialize config_file
end
@path = config_file

config_hash = DEFAULT_CONFIG.merge(YAML.load_file(config_file))
config_hash = DEFAULT_CONFIG.merge(YAML.load(ERB.new(File.read(config_file)).result))
config_hash.each do |k, v|
writer_method = "#{k}="
if respond_to?(writer_method)
Expand Down
26 changes: 26 additions & 0 deletions spec/gemnasium/configuration_spec.rb
Expand Up @@ -69,6 +69,32 @@ def write_config_file
it { expect(config.ignored_paths).to include Regexp.new("^[^\/]+\\.gemspec") }
end
end

context 'for a config file with parsable ERB code' do
before { write_config_file }
before { ENV['GEMNASIUM_API_KEY'] = 'api_key_from_env' }

let(:config_options) do
{
api_key: "<%= ENV['GEMNASIUM_API_KEY'] %>",
project_name: 'gemnasium-gem',
project_branch: 'master',
ignored_paths: ['spec/','tmp/*.lock', '*.gemspec']
}
end

it 'parses ERB code' do
expect(config.api_key).to eql 'api_key_from_env'
end

it 'keeps values unchanged if not ERB code' do
expect(config.project_name).to eql config_options[:project_name]
expect(config.project_branch).to eql config_options[:project_branch]
expect(config.ignored_paths).to include Regexp.new("^spec/")
expect(config.ignored_paths).to include Regexp.new("^tmp/[^/]+\\.lock")
expect(config.ignored_paths).to include Regexp.new("^[^\/]+\\.gemspec")
end
end
end

pending "writable?"
Expand Down

0 comments on commit 2be15d1

Please sign in to comment.