Skip to content
Browse files

add yml configuration

  • Loading branch information...
1 parent 51b506d commit af14a952abd7f2644a2dba544d4b96a132f488db @phoet phoet committed Mar 16, 2011
Showing with 25 additions and 0 deletions.
  1. +12 −0 lib/asin/configuration.rb
  2. +4 −0 spec/asin.yml
  3. +9 −0 spec/asin_spec.rb
View
12 lib/asin/configuration.rb
@@ -1,3 +1,5 @@
+require "yaml"
+
module ASIN
class Configuration
class << self
@@ -28,13 +30,23 @@ def configure(options={})
init_config
if block_given?
yield self
+ elsif yml_path = options[:yaml] || options[:yml]
+ File.open(yml_path) { |file| YAML.load(file) }.each do |key, value|
+ send(:"#{key}=", value)
+ end
else
options.each do |key, value|
send(:"#{key}=", value)
end
end
self
end
+
+ # Resets configuration to defaults
+ #
+ def reset
+ init_config(true)
+ end
private
View
4 spec/asin.yml
@@ -0,0 +1,4 @@
+secret: 'secret'
+key: 'key'
+host: 'host'
+logger: 'logger'
View
9 spec/asin_spec.rb
@@ -32,10 +32,19 @@
end
config.key.should eql('bla')
end
+
+ it "should read configuration from yml" do
+ config = ASIN::Configuration.configure :yaml => 'spec/asin.yml'
+ config.secret.should eql('secret')
+ config.key.should eql('key')
+ config.host.should eql('host')
+ config.logger.should eql('logger')
+ end
end
context "lookup and search" do
before do
+ ASIN::Configuration.reset
@helper.configure :secret => @secret, :key => @key
end

0 comments on commit af14a95

Please sign in to comment.
Something went wrong with that request. Please try again.