Permalink
Browse files

Merge branch 'feature/yml' into develop

  • Loading branch information...
2 parents 51b506d + 7d95487 commit a9917ba163f9526bce0cdabd026cd74913673507 @phoet phoet committed Mar 19, 2011
Showing with 70 additions and 16 deletions.
  1. +6 −6 Gemfile.lock
  2. +5 −1 README.rdoc
  3. +32 −7 lib/asin/configuration.rb
  4. +1 −1 lib/asin/version.rb
  5. +1 −1 rakefile.rb
  6. +4 −0 spec/asin.yml
  7. +21 −0 spec/asin_spec.rb
View
@@ -1,35 +1,35 @@
PATH
remote: .
specs:
- asin (0.3.0)
+ asin (0.4.0)
crack (~> 0.1.8)
hashie (~> 1.0.0)
httpi (~> 0.7.9)
GEM
remote: http://rubygems.org/
specs:
+ chalofa_ruby-progressbar (0.0.9.1)
crack (0.1.8)
diff-lcs (1.1.2)
- fuubar (0.0.3)
+ fuubar (0.0.4)
+ chalofa_ruby-progressbar (~> 0.0.9)
rspec (~> 2.0)
rspec-instafail (~> 0.1.4)
- ruby-progressbar (~> 0.0.9)
hashie (1.0.0)
httpclient (2.1.6.1)
httpi (0.7.9)
rack
- rack (1.2.1)
+ rack (1.2.2)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
- rspec-instafail (0.1.5)
+ rspec-instafail (0.1.7)
rspec-mocks (2.4.0)
- ruby-progressbar (0.0.9)
PLATFORMS
ruby
View
@@ -8,7 +8,11 @@ The gem is tested against 1.9.2, 1.9.1 and 1.8.7 (compatibility with Heroku-Bamb
== Configuration
-Since Version 0.2.0 ASIN provides a Rails-Style configuration.
+Since Version 0.4.0 ASIN provides a YAML Configuration:
+
+ ASIN::Configuration.configure :yaml => 'config/asin.yml'
+
+Since Version 0.2.0 ASIN provides a Rails-Style Configuration.
You can put this in a initializer (config/initializers/asin.rb):
View
@@ -1,32 +1,51 @@
+require "yaml"
+
module ASIN
class Configuration
class << self
attr_accessor :secret, :key, :host, :logger
# Rails initializer configuration.
- #
+ #
# Expects at least +secret+ and +key+ for the API call:
- #
+ #
# ASIN::Configuration.configure do |config|
# config.secret = 'your-secret'
# config.key = 'your-key'
# end
#
# You may pass options as a hash as well:
#
- # ASIN::Configuration.configure(:secret => 'your-secret', :key => 'your-key')
- #
+ # ASIN::Configuration.configure :secret => 'your-secret', :key => 'your-key'
+ #
+ # Or configure everything using YAML:
+ #
+ # ASIN::Configuration.configure :yaml => 'config/asin.yml'
+ #
+ # ASIN::Configuration.configure :yaml => 'config/asin.yml' do |config, yml|
+ # config.key = yml[Rails.env]['aws_access_key']
+ # end
+ #
# ==== Options:
- #
+ #
# [secret] the API secret key
# [key] the API access key
# [host] the host, which defaults to 'webservices.amazon.com'
# [logger] a different logger than logging to STDERR (nil for no logging)
- #
+ #
def configure(options={})
init_config
- if block_given?
+ if yml_path = options[:yaml] || options[:yml]
+ yml = File.open(yml_path) { |file| YAML.load(file) }
+ if block_given?
+ yield self, yml
+ else
+ yml.each do |key, value|
+ send(:"#{key}=", value)
+ end
+ end
+ elsif block_given?
yield self
else
options.each do |key, value|
@@ -35,6 +54,12 @@ def configure(options={})
end
self
end
+
+ # Resets configuration to defaults
+ #
+ def reset
+ init_config(true)
+ end
private
View
@@ -1,3 +1,3 @@
module ASIN
- VERSION = "0.3.0"
+ VERSION = "0.4.0"
end
View
@@ -38,5 +38,5 @@
task :travis_ci do
puts "WE LOOOOOOOOOOOOVE"
Rake::Task['spec'].invoke
- puts "TRAVIS CI"
+ puts "TRAVIS CI!!!!!!!!!!!!!!!oneeleven"
end
View
@@ -0,0 +1,4 @@
+secret: 'secret_yml'
+key: 'key_yml'
+host: 'host_yml'
+logger: 'logger_yml'
View
@@ -7,6 +7,10 @@
@key = ENV['ASIN_KEY']
puts "configure #{@secret} and #{@key} for this test"
end
+
+ after do
+ ASIN::Configuration.reset
+ end
context "configuration" do
it "should fail without secret and key" do
@@ -32,6 +36,23 @@
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_yml')
+ config.key.should eql('key_yml')
+ config.host.should eql('host_yml')
+ config.logger.should eql('logger_yml')
+ end
+
+ it "should read configuration from yml with block" do
+ config = ASIN::Configuration.configure :yaml => 'spec/asin.yml' do |config, yml|
+ config.secret = nil
+ config.key = yml['secret']
+ end
+ config.secret.should be_nil
+ config.key.should eql('secret_yml')
+ end
end
context "lookup and search" do

0 comments on commit a9917ba

Please sign in to comment.