aws-ext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Les Hill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ = aws-ext
2
+
3
+ Extensions for the aws-s3 gem
4
+
5
+ == Installing
6
+
7
+ % sudo gem install aws-ext --source http://gemcutter.org
8
+
9
+ == S3Object
10
+
11
+ === .copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
12
+
13
+ Copies arbitrary S3Object across buckets using the Amazon S3 copy option. ACLs default to :public_read. Passing :copy as the ACL will copy the sources ACL.
14
+
15
+ === #copy_to_bucket(dest_bucket, dest_key = nil, acl_policy = :copy
16
+
17
+ Copies this S3Object across buckets using the Amazon S3 copy option. Destination key defaults to Source key.ACLs default to :public_read. Passing :copy as the ACL will copy the sources ACL.
18
+
19
+ == Bucket
20
+
21
+ === #exists?(key)
22
+
23
+ Does key exist in this bucket?
24
+
25
+ === #find(key)
26
+
27
+ Find key in this bucket.
28
+
29
+ === #each_object(opts = {}, &block)
30
+
31
+ Paginates over all objects in the bucket. :max_keys defaults to 100.
32
+
33
+ == Note on Patches/Pull Requests
34
+
35
+ * Fork the project.
36
+ * Make your feature addition or bug fix.
37
+ * Add tests for it. This is important so I don't break it in a
38
+ future version unintentionally.
39
+ * Commit, do not mess with rakefile, version, or history.
40
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
41
+ * Send me a pull request. Bonus points for topic branches.
42
+
43
+ == Copyright
44
+
45
+ Copyright (c) 2009 Les Hill. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "aws-ext"
8
+ gem.summary = %Q{Extensions for aws-s3}
9
+ gem.description = %Q{Extensions for aws-s3}
10
+ gem.email = "leshill@gmail.com"
11
+ gem.homepage = "http://github.com/leshill/aws-ext"
12
+ gem.authors = ["Les Hill"]
13
+ gem.add_dependency "aws-s3", ">= 0.6.2"
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "aws-ext #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/aws-ext.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{aws-ext}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Les Hill"]
12
+ s.date = %q{2009-11-21}
13
+ s.description = %q{Extensions for aws-s3}
14
+ s.email = %q{leshill@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "aws-ext.gemspec",
27
+ "lib/aws-ext.rb",
28
+ "spec/aws-ext_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/leshill/aws-ext}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Extensions for aws-s3}
37
+ s.test_files = [
38
+ "spec/aws-ext_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<aws-s3>, [">= 0.6.2"])
48
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49
+ else
50
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ end
57
+ end
58
+
data/lib/aws-ext.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'aws/s3'
2
+
3
+ module AWS
4
+ module S3
5
+ class S3Object
6
+ def self.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
7
+ headers = {'x-amz-copy-source' => path!(src_bucket, src_key)}
8
+ if acl_policy == :copy
9
+ returning put(path!(dest_bucket, dest_key), headers) do
10
+ acl(dest_key, dest_bucket, acl(src_key, src_bucket))
11
+ end
12
+ else
13
+ headers['x-amz-acl'] = acl_policy
14
+ put(path!(dest_bucket, dest_key), headers)
15
+ end
16
+ end
17
+
18
+ def copy_to_bucket(dest_bucket, dest_key = nil, acl_policy = :copy)
19
+ self.class.copy_across_buckets(bucket.name, key, dest_bucket.name, dest_key ? dest_key : key, acl_policy)
20
+ end
21
+ end
22
+
23
+ class Bucket
24
+ def each_object(opts = {}, &block)
25
+ opts = { :max_keys => 100 }.merge(opts)
26
+ while (response = objects(opts).each {|obj| yield obj }).any? do
27
+ opts[:marker] = response.last.key
28
+ end
29
+ end
30
+
31
+ def exists?(key)
32
+ S3Object.exists?(key, name)
33
+ end
34
+
35
+ def find(key)
36
+ S3Object.find(key, name)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+
3
+ describe 'aws_ext' do
4
+ context "AWS::S3::Bucket" do
5
+ it "#exists? delegates to S3Object.exists?" do
6
+ key = 'key'
7
+ name = 'bucket'
8
+ AWS::S3::S3Object.should_receive(:exists?).with(key, name)
9
+ AWS::S3::Bucket.new(:name => name).exists?(key)
10
+ end
11
+
12
+ it "#find delegates to S3Object.find" do
13
+ key = 'key'
14
+ name = 'bucket'
15
+ AWS::S3::S3Object.should_receive(:find).with(key, name)
16
+ AWS::S3::Bucket.new(:name => name).find(key)
17
+ end
18
+
19
+ it "#each_object calls objects with max_keys and marker set" do
20
+ key = 'key'
21
+ initial_opts = {:max_keys => 1}
22
+ initial_return = [stub('object', :key => key)]
23
+ second_opts = {:max_keys => 1}
24
+ second_opts[:marker] = key
25
+ bucket = AWS::S3::Bucket.new(:name => 'bucket')
26
+ bucket.should_receive(:objects).with(initial_opts).and_return(initial_return)
27
+ bucket.should_receive(:objects).with(second_opts).and_return([])
28
+ bucket.each_object(initial_opts) {}
29
+ end
30
+ end
31
+
32
+ context "AWS::S3::S3Object" do
33
+ it "#copy_to_bucket delegates to S3Object.copy_across_buckets with defaults" do
34
+ key = 'key'
35
+ src_bucket_name = 'src_bucket'
36
+ src_bucket = AWS::S3::Bucket.new(:name => src_bucket_name)
37
+ dest_bucket_name = 'dest_bucket'
38
+ dest_bucket = AWS::S3::Bucket.new(:name => dest_bucket_name)
39
+ AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket_name, key, dest_bucket_name, key, :copy)
40
+ AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => key).copy_to_bucket(dest_bucket)
41
+ end
42
+
43
+ it "#copy_to_bucket delegates to S3Object.copy_across_buckets without defaults" do
44
+ acl = :public_read
45
+ src_key = 'src_key'
46
+ dest_key = 'dest_key'
47
+ src_bucket_name = 'src_bucket'
48
+ src_bucket = AWS::S3::Bucket.new(:name => src_bucket_name)
49
+ dest_bucket_name = 'dest_bucket'
50
+ dest_bucket = AWS::S3::Bucket.new(:name => dest_bucket_name)
51
+ AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket_name, src_key, dest_bucket_name, dest_key, acl)
52
+ AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => src_key).copy_to_bucket(dest_bucket, dest_key, acl)
53
+ end
54
+
55
+ it ".copy_across_buckets when passed an acl_policy that is not :copy just puts the copy" do
56
+ acl = :public_read
57
+ src_key = 'src_key'
58
+ dest_key = 'dest_key'
59
+ src_bucket = 'src_bucket'
60
+ dest_bucket = 'dest_bucket'
61
+ headers = {}
62
+ headers['x-amz-copy-source'] = AWS::S3::S3Object.path!(src_bucket, src_key)
63
+ headers['x-amz-acl'] = acl
64
+ AWS::S3::S3Object.should_receive(:put).with(AWS::S3::S3Object.path!(dest_bucket, dest_key), headers)
65
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, :public_read)
66
+ end
67
+
68
+ it ".copy_across_buckets when passed a :copy acl_policy puts the copy and copies the acl" do
69
+ acl = :copy
70
+ src_key = 'src_key'
71
+ dest_key = 'dest_key'
72
+ src_bucket = 'src_bucket'
73
+ dest_bucket = 'dest_bucket'
74
+ headers = {}
75
+ headers['x-amz-copy-source'] = AWS::S3::S3Object.path!(src_bucket, src_key)
76
+ returned_acl = 'returned_acl'
77
+ AWS::S3::S3Object.should_receive(:acl).with(src_key, src_bucket).and_return(returned_acl)
78
+ AWS::S3::S3Object.should_receive(:acl).with(dest_key, dest_bucket, returned_acl)
79
+ AWS::S3::S3Object.should_receive(:put).with(AWS::S3::S3Object.path!(dest_bucket, dest_key), headers)
80
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl)
81
+ end
82
+
83
+ end
84
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'aws-ext'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Les Hill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-21 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: aws-s3
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ description: Extensions for aws-s3
36
+ email: leshill@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - aws-ext.gemspec
52
+ - lib/aws-ext.rb
53
+ - spec/aws-ext_spec.rb
54
+ - spec/spec.opts
55
+ - spec/spec_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/leshill/aws-ext
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Extensions for aws-s3
84
+ test_files:
85
+ - spec/aws-ext_spec.rb
86
+ - spec/spec_helper.rb