Merge branch 'master' of git://github.com/marcandre/aws-s3 into marcandre/master

This commit is contained in:
Marcel Molina 2009-04-19 17:07:12 -07:00
Родитель 7b76018725 1191298b40
Коммит e2a13a6366
3 изменённых файлов: 11 добавлений и 57 удалений

Просмотреть файл

@ -249,22 +249,13 @@ module AWS
end
class Options < Hash #:nodoc:
class << self
def valid_options
[:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy]
end
end
VALID_OPTIONS = [:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy].freeze
attr_reader :options
def initialize(options = {})
super()
@options = options
validate!
extract_proxy_settings!
extract_persistent!
extract_server!
extract_port!
extract_remainder!
validate(options)
replace(:server => DEFAULT_HOST, :port => (options[:use_ssl] ? 443 : 80))
merge!(options)
end
def connecting_through_proxy?
@ -272,50 +263,14 @@ module AWS
end
def proxy_settings
proxy_setting_keys.map do |proxy_key|
self[:proxy][proxy_key]
end
self[:proxy].values_at(:host, :port, :user, :password)
end
private
def proxy_setting_keys
[:host, :port, :user, :password]
end
def missing_proxy_settings?
!self[:proxy].keys.include?(:host)
end
def extract_persistent!
self[:persistent] = options.has_key?(:persitent) ? options[:persitent] : false
end
def extract_proxy_settings!
self[:proxy] = options.delete(:proxy) if options.include?(:proxy)
validate_proxy_settings!
end
def extract_server!
self[:server] = options.delete(:server) || DEFAULT_HOST
end
def extract_port!
self[:port] = options.delete(:port) || (options[:use_ssl] ? 443 : 80)
end
def extract_remainder!
update(options)
end
def validate!
invalid_options = options.keys.select {|key| !self.class.valid_options.include?(key)}
def validate(options)
invalid_options = options.keys - VALID_OPTIONS
raise InvalidConnectionOption.new(invalid_options) unless invalid_options.empty?
end
def validate_proxy_settings!
if connecting_through_proxy? && missing_proxy_settings?
raise ArgumentError, "Missing proxy settings. Must specify at least :host."
end
raise ArgumentError, "Missing proxy settings. Must specify at least :host." if options[:proxy] && !options[:proxy][:host]
end
end
end

Просмотреть файл

@ -58,7 +58,7 @@ module AWS
class InvalidConnectionOption < InvalidOption
def initialize(invalid_options)
message = "The following connection options are invalid: #{invalid_options.join(', ')}. " +
"The valid connection options are: #{Connection::Options.valid_options.join(', ')}."
"The valid connection options are: #{Connection::Options::VALID_OPTIONS.join(', ')}."
super(message)
end
end

Просмотреть файл

@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/test_helper'
class ConnectionTest < Test::Unit::TestCase
attr_reader :keys
def setup
@keys = {:access_key_id => '123', :secret_access_key => 'abc'}
@keys = {:access_key_id => '123', :secret_access_key => 'abc'}.freeze
end
def test_creating_a_connection
@ -207,7 +207,6 @@ class ConnectionOptionsTest < Test::Unit::TestCase
private
def assert_key_transfered(key, value, options)
assert_equal value, options[key]
assert !options.instance_variable_get('@options').has_key?(key)
end
def generate_options(options = {})