Skip to content
Browse files

Removed unused extensions that conflict with aws-s3

  • Loading branch information...
1 parent 5d92b6e commit be7492471603265c2a9e0421ee33b8c9a9637b11 Drew Blas committed Feb 3, 2011
Showing with 0 additions and 340 deletions.
  1. +0 −169 lib/aws/ses/extensions.rb
  2. +0 −171 test/extensions_test.rb
View
169 lib/aws/ses/extensions.rb
@@ -1,30 +1,4 @@
#:stopdoc:
-
-class Hash
- def to_query_string(include_question_mark = true)
- query_string = ''
- unless empty?
- query_string << '?' if include_question_mark
- query_string << inject([]) do |params, (key, value)|
- params << "#{key}=#{value}"
- end.join('&')
- end
- query_string
- end
-
- def to_normalized_options
- # Convert all option names to downcased strings, and replace underscores with hyphens
- inject({}) do |normalized_options, (name, value)|
- normalized_options[name.to_header] = value.to_s
- normalized_options
- end
- end
-
- def to_normalized_options!
- replace(to_normalized_options)
- end
-end
-
class String
if RUBY_VERSION <= '1.9'
def previous!
@@ -90,34 +64,6 @@ def remove_extended
end
end
-class CoercibleString < String
- class << self
- def coerce(string)
- new(string).coerce
- end
- end
-
- def coerce
- case self
- when 'true'; true
- when 'false'; false
- # Don't coerce numbers that start with zero
- when /^[1-9]+\d*$/; Integer(self)
- when datetime_format; Time.parse(self)
- else
- self
- end
- end
-
- private
- # Lame hack since Date._parse is so accepting. S3 dates are of the form: '2006-10-29T23:14:47.000Z'
- # so unless the string looks like that, don't even try, otherwise it might convert an object's
- # key from something like '03 1-2-3-Apple-Tree.mp3' to Sat Feb 03 00:00:00 CST 2001.
- def datetime_format
- /^\d{4}-\d{2}-\d{2}\w\d{2}:\d{2}:\d{2}/
- end
-end
-
class Symbol
def to_header
to_s.to_header
@@ -161,13 +107,6 @@ def require_library_or_gem(library, gem_name = nil)
end
end
-class Object
- def returning(value)
- yield(value)
- value
- end
-end
-
class Module
def memoized(method_name)
original_method = "unmemoized_#{method_name}_#{Time.now.to_i}"
@@ -191,114 +130,6 @@ def self.#{name.to_s.downcase}
EVAL
end
end
-
- # Transforms MarcelBucket into
- #
- # class MarcelBucket < AWS::S3::Bucket
- # set_current_bucket_to 'marcel'
- # end
- def const_missing_from_s3_library(sym)
- if sym.to_s =~ /^(\w+)(Bucket|S3Object)$/
- const = const_set(sym, Class.new(AWS::S3.const_get($2)))
- const.current_bucket = $1.underscore
- const
- else
- const_missing_not_from_s3_library(sym)
- end
- end
- alias_method :const_missing_not_from_s3_library, :const_missing
- alias_method :const_missing, :const_missing_from_s3_library
-end
-
-
-class Class # :nodoc:
- def cattr_reader(*syms)
- syms.flatten.each do |sym|
- class_eval(<<-EOS, __FILE__, __LINE__)
- unless defined? @@#{sym}
- @@#{sym} = nil
- end
-
- def self.#{sym}
- @@#{sym}
- end
-
- def #{sym}
- @@#{sym}
- end
- EOS
- end
- end
-
- def cattr_writer(*syms)
- syms.flatten.each do |sym|
- class_eval(<<-EOS, __FILE__, __LINE__)
- unless defined? @@#{sym}
- @@#{sym} = nil
- end
-
- def self.#{sym}=(obj)
- @@#{sym} = obj
- end
-
- def #{sym}=(obj)
- @@#{sym} = obj
- end
- EOS
- end
- end
-
- def cattr_accessor(*syms)
- cattr_reader(*syms)
- cattr_writer(*syms)
- end
-end if Class.instance_methods(false).grep(/^cattr_(?:reader|writer|accessor)$/).empty?
-
-module SelectiveAttributeProxy
- def self.included(klass)
- klass.extend(ClassMethods)
- klass.class_eval(<<-EVAL, __FILE__, __LINE__)
- cattr_accessor :attribute_proxy
- cattr_accessor :attribute_proxy_options
-
- # Default name for attribute storage
- self.attribute_proxy = :attributes
- self.attribute_proxy_options = {:exclusively => true}
-
- private
- # By default proxy all attributes
- def proxiable_attribute?(name)
- return true unless self.class.attribute_proxy_options[:exclusively]
- send(self.class.attribute_proxy).has_key?(name)
- end
-
- def method_missing(method, *args, &block)
- # Autovivify attribute storage
- if method == self.class.attribute_proxy
- ivar = "@\#{method}"
- instance_variable_set(ivar, {}) unless instance_variable_get(ivar).is_a?(Hash)
- instance_variable_get(ivar)
- # Delegate to attribute storage
- elsif method.to_s =~ /^(\\w+)(=?)$/ && proxiable_attribute?($1)
- attributes_hash_name = self.class.attribute_proxy
- $2.empty? ? send(attributes_hash_name)[$1] : send(attributes_hash_name)[$1] = args.first
- else
- super
- end
- end
- EVAL
- end
-
- module ClassMethods
- def proxy_to(attribute_name, options = {})
- if attribute_name.is_a?(Hash)
- options = attribute_name
- else
- self.attribute_proxy = attribute_name
- end
- self.attribute_proxy_options = options
- end
- end
end
View
171 test/extensions_test.rb
@@ -1,46 +1,5 @@
require File.dirname(__FILE__) + '/helper'
-class HashExtensionsTest < Test::Unit::TestCase
- def test_to_query_string
- # Because hashes aren't ordered, I'm mostly testing against hashes with just one key
- symbol_keys = {:one => 1}
- string_keys = {'one' => 1}
- expected = '?one=1'
- [symbol_keys, string_keys].each do |hash|
- assert_equal expected, hash.to_query_string
- end
- end
-
- def test_empty_hash_returns_no_query_string
- assert_equal '', {}.to_query_string
- end
-
- def test_include_question_mark
- hash = {:one => 1}
- assert_equal '?one=1', hash.to_query_string
- assert_equal 'one=1', hash.to_query_string(false)
- end
-
- def test_elements_joined_by_ampersand
- hash = {:one => 1, :two => 2}
- qs = hash.to_query_string
- assert qs['one=1&two=2'] || qs['two=2&one=1']
- end
-
- def test_normalized_options
- expectations = [
- [{:foo_bar => 1}, {'foo-bar' => '1'}],
- [{'foo_bar' => 1}, {'foo-bar' => '1'}],
- [{'foo-bar' => 1}, {'foo-bar' => '1'}],
- [{}, {}]
- ]
-
- expectations.each do |(before, after)|
- assert_equal after, before.to_normalized_options
- end
- end
-end
-
class StringExtensionsTest < Test::Unit::TestCase
def test_previous
expectations = {'abc' => 'abb', '123' => '122', '1' => '0'}
@@ -76,28 +35,6 @@ def test_remove_extended
end
end
-class CoercibleStringTest < Test::Unit::TestCase
-
- def test_coerce
- coercions = [
- ['1', 1],
- ['false', false],
- ['true', true],
- ['2006-10-29T23:14:47.000Z', Time.parse('2006-10-29T23:14:47.000Z')],
- ['Hello!', 'Hello!'],
- ['false23', 'false23'],
- ['03 1-2-3-Apple-Tree.mp3', '03 1-2-3-Apple-Tree.mp3'],
- ['0815', '0815'] # This number isn't coerced because the leading zero would be lost
- ]
-
- coercions.each do |before, after|
- assert_nothing_raised do
- assert_equal after, CoercibleString.coerce(before)
- end
- end
- end
-end
-
class KerneltExtensionsTest < Test::Unit::TestCase
class Foo
def foo
@@ -230,111 +167,3 @@ def instance_variables_of(object)
end
end
-
-class AttributeProxyTest < Test::Unit::TestCase
- class BlindProxyUsingDefaultAttributesHash
- include SelectiveAttributeProxy
- proxy_to :exlusively => false
- end
-
- class BlindProxyUsingCustomAttributeHash
- include SelectiveAttributeProxy
- proxy_to :settings
- end
-
- class ProxyUsingPassedInAttributeHash
- include SelectiveAttributeProxy
-
- def initialize(attributes = {})
- @attributes = attributes
- end
- end
-
- class RestrictedProxy
- include SelectiveAttributeProxy
-
- private
- def proxiable_attribute?(name)
- %w(foo bar baz).include?(name)
- end
- end
-
- class NonExclusiveProxy
- include SelectiveAttributeProxy
- proxy_to :settings, :exclusively => false
- end
-
- def test_using_all_defaults
- b = BlindProxyUsingDefaultAttributesHash.new
- assert_nothing_raised do
- b.foo = 'bar'
- end
-
- assert_nothing_raised do
- b.foo
- end
-
- assert_equal 'bar', b.foo
- end
-
- def test_storage_is_autovivified
- b = BlindProxyUsingDefaultAttributesHash.new
- assert_nothing_raised do
- b.send(:attributes)['foo'] = 'bar'
- end
-
- assert_nothing_raised do
- b.foo
- end
-
- assert_equal 'bar', b.foo
- end
-
- def test_limiting_which_attributes_are_proxiable
- r = RestrictedProxy.new
- assert_nothing_raised do
- r.foo = 'bar'
- end
-
- assert_nothing_raised do
- r.foo
- end
-
- assert_equal 'bar', r.foo
-
- assert_raises(NoMethodError) do
- r.quux = 'foo'
- end
-
- assert_raises(NoMethodError) do
- r.quux
- end
- end
-
- def test_proxying_is_exclusive_by_default
- p = ProxyUsingPassedInAttributeHash.new('foo' => 'bar')
- assert_nothing_raised do
- p.foo
- p.foo = 'baz'
- end
-
- assert_equal 'baz', p.foo
-
- assert_raises(NoMethodError) do
- p.quux
- end
- end
-
- def test_setting_the_proxy_as_non_exclusive
- n = NonExclusiveProxy.new
- assert_nothing_raised do
- n.foo = 'baz'
- end
-
- assert_nothing_raised do
- n.foo
- end
-
- assert_equal 'baz', n.foo
- end
-end

0 comments on commit be74924

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