Skip to content
Browse files

Split the AwsLibrary and AwsS3Library mixins out into their own files.

  • Loading branch information...
1 parent 201f1f3 commit 78b197122adc9ca89aa60dbc4527cbbaf36e2d76 @postmodern postmodern committed with solnic
View
4 dm-paperclip.gemspec
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ken Robertson"]
- s.date = %q{2010-10-09}
+ s.date = %q{2010-10-12}
s.email = %q{ken@invalidlogic.com}
s.extra_rdoc_files = ["README.rdoc"]
- s.files = ["README.rdoc", "LICENSE", "Rakefile", "init.rb", "lib/dm-paperclip.rb", "lib/dm-paperclip", "lib/dm-paperclip/validations.rb", "lib/dm-paperclip/geometry.rb", "lib/dm-paperclip/storage", "lib/dm-paperclip/storage/s3.rb", "lib/dm-paperclip/storage/filesystem.rb", "lib/dm-paperclip/iostream.rb", "lib/dm-paperclip/storage.rb", "lib/dm-paperclip/thumbnail.rb", "lib/dm-paperclip/attachment.rb", "lib/dm-paperclip/upfile.rb", "lib/dm-paperclip/callback_compatability.rb", "lib/dm-paperclip/processor.rb", "lib/dm-paperclip/interpolations.rb", "tasks/paperclip_tasks.rake", "test/paperclip_test.rb", "test/attachment_test.rb", "test/geometry_test.rb", "test/integration_test.rb", "test/iostream_test.rb", "test/fixtures", "test/fixtures/5k.png", "test/fixtures/bad.png", "test/fixtures/s3.yml", "test/fixtures/50x50.png", "test/fixtures/text.txt", "test/fixtures/12k.png", "test/storage_test.rb", "test/helper.rb", "test/thumbnail_test.rb"]
+ s.files = ["README.rdoc", "LICENSE", "Rakefile", "init.rb", "lib/dm-paperclip.rb", "lib/dm-paperclip", "lib/dm-paperclip/validations.rb", "lib/dm-paperclip/geometry.rb", "lib/dm-paperclip/storage", "lib/dm-paperclip/storage/s3.rb", "lib/dm-paperclip/storage/filesystem.rb", "lib/dm-paperclip/storage/s3", "lib/dm-paperclip/storage/s3/aws_library.rb", "lib/dm-paperclip/storage/s3/aws_s3_library.rb", "lib/dm-paperclip/iostream.rb", "lib/dm-paperclip/storage.rb", "lib/dm-paperclip/thumbnail.rb", "lib/dm-paperclip/attachment.rb", "lib/dm-paperclip/upfile.rb", "lib/dm-paperclip/callback_compatability.rb", "lib/dm-paperclip/processor.rb", "lib/dm-paperclip/interpolations.rb", "tasks/paperclip_tasks.rake", "test/paperclip_test.rb", "test/attachment_test.rb", "test/geometry_test.rb", "test/integration_test.rb", "test/iostream_test.rb", "test/fixtures", "test/fixtures/5k.png", "test/fixtures/bad.png", "test/fixtures/s3.yml", "test/fixtures/50x50.png", "test/fixtures/text.txt", "test/fixtures/12k.png", "test/storage_test.rb", "test/helper.rb", "test/thumbnail_test.rb"]
s.homepage = %q{http://invalidlogic.com/dm-paperclip/}
s.rdoc_options = ["--line-numbers", "--inline-source"]
s.require_paths = ["lib"]
View
88 lib/dm-paperclip/storage/s3.rb
@@ -1,3 +1,6 @@
+require 'dm-paperclip/storage/s3/aws_s3_library'
+require 'dm-paperclip/storage/s3/aws_library'
+
module Paperclip
module Storage
# Amazon's S3 file hosting service is a scalable, easy place to store
@@ -76,90 +79,6 @@ module Storage
# does not support directories, you can still use a / to separate
# parts of your file name.
module S3
- # Mixin which interfaces with the 'aws' and 'right_aws' libraries.
- module AwsLibrary
- protected
-
- def s3_connect!
- @s3 = Aws::S3.new(
- @s3_credentials[:access_key_id],
- @s3_credentials[:secret_access_key]
- )
- @s3_bucket = @s3.bucket(bucket_name)
- end
-
- def s3_expiring_url(key,time)
- @s3.interface.get_link(bucket_name,key,time)
- end
-
- def s3_exists?(key)
- @s3_bucket.keys(:prefix => key).any? { |s3_key| s3_key.name == key }
- end
-
- def s3_download(key,file)
- @s3_bucket.key(key).get { |chunk| file.write(chunk) }
- end
-
- def s3_store(key,file)
- @s3_bucket.key(key).put(
- file,
- @s3_permissions.to_s.gsub('_','-')
- )
- end
-
- def s3_delete(key)
- @s3_bucket.key(key).delete
- end
- end
-
- # Mixin which interfaces with the 'aws-s3' library.
- module AwsS3Library
- protected
-
- def s3_connect!
- AWS::S3::Base.establish_connection!(@s3_options.merge(
- :access_key_id => @s3_credentials[:access_key_id],
- :secret_access_key => @s3_credentials[:secret_access_key]
- ))
- end
-
- def s3_expiring_url(key,time)
- AWS::S3::S3Object.url_for(key, bucket_name, :expires_in => time)
- end
-
- def s3_exists?(key)
- AWS::S3::S3Object.exists?(key, bucket_name)
- end
-
- def s3_download(key,file)
- file.write(AWS::S3::S3Object.value(key, bucket_name))
- end
-
- def s3_store(key,file)
- begin
- AWS::S3::S3Object.store(
- key,
- file,
- bucket_name,
- {
- :content_type => instance_read(:content_type),
- :access => @s3_permissions,
- }.merge(@s3_headers)
- )
- rescue AWS::S3::ResponseError => e
- raise
- end
- end
-
- def s3_delete(key)
- begin
- AWS::S3::S3Object.delete(key, bucket_name)
- rescue AWS::S3::ResponseError
- # Ignore this.
- end
- end
- end
-
# Libraries and mixins that provide S3 support
LIBRARIES = {
'aws/s3' => AwsS3Library,
@@ -298,7 +217,6 @@ def find_credentials(creds)
raise ArgumentError, 'Credentials are not a path, file, or hash.'
end
end
-
end
end
end
View
41 lib/dm-paperclip/storage/s3/aws_library.rb
@@ -0,0 +1,41 @@
+module Paperclip
+ module Storage
+ module S3
+ # Mixin which interfaces with the 'aws' and 'right_aws' libraries.
+ module AwsLibrary
+ protected
+
+ def s3_connect!
+ @s3 = Aws::S3.new(
+ @s3_credentials[:access_key_id],
+ @s3_credentials[:secret_access_key]
+ )
+ @s3_bucket = @s3.bucket(bucket_name)
+ end
+
+ def s3_expiring_url(key,time)
+ @s3.interface.get_link(bucket_name,key,time)
+ end
+
+ def s3_exists?(key)
+ @s3_bucket.keys(:prefix => key).any? { |s3_key| s3_key.name == key }
+ end
+
+ def s3_download(key,file)
+ @s3_bucket.key(key).get { |chunk| file.write(chunk) }
+ end
+
+ def s3_store(key,file)
+ @s3_bucket.key(key).put(
+ file,
+ @s3_permissions.to_s.gsub('_','-')
+ )
+ end
+
+ def s3_delete(key)
+ @s3_bucket.key(key).delete
+ end
+ end
+ end
+ end
+end
View
53 lib/dm-paperclip/storage/s3/aws_s3_library.rb
@@ -0,0 +1,53 @@
+module Paperclip
+ module Storage
+ module S3
+ # Mixin which interfaces with the 'aws-s3' library.
+ module AwsS3Library
+ protected
+
+ def s3_connect!
+ AWS::S3::Base.establish_connection!(@s3_options.merge(
+ :access_key_id => @s3_credentials[:access_key_id],
+ :secret_access_key => @s3_credentials[:secret_access_key]
+ ))
+ end
+
+ def s3_expiring_url(key,time)
+ AWS::S3::S3Object.url_for(key, bucket_name, :expires_in => time)
+ end
+
+ def s3_exists?(key)
+ AWS::S3::S3Object.exists?(key, bucket_name)
+ end
+
+ def s3_download(key,file)
+ file.write(AWS::S3::S3Object.value(key, bucket_name))
+ end
+
+ def s3_store(key,file)
+ begin
+ AWS::S3::S3Object.store(
+ key,
+ file,
+ bucket_name,
+ {
+ :content_type => instance_read(:content_type),
+ :access => @s3_permissions,
+ }.merge(@s3_headers)
+ )
+ rescue AWS::S3::ResponseError => e
+ raise
+ end
+ end
+
+ def s3_delete(key)
+ begin
+ AWS::S3::S3Object.delete(key, bucket_name)
+ rescue AWS::S3::ResponseError
+ # Ignore this.
+ end
+ end
+ end
+ end
+ end
+end

0 comments on commit 78b1971

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