rpbertp13-dm-s3 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,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Roberto Thais
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,7 @@
1
+ = dm-s3
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Roberto Thais. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dm-s3"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "roberto.n.thais@gmail.com"
10
+ gem.homepage = "http://github.com/rpbertp13/dm-s3"
11
+ gem.authors = ["Roberto Thais"]
12
+ gem.add_dependency('aws-s3', '>= 0.6.2')
13
+ gem.add_dependency('dm-core', '>= 0.9.11')
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION.yml')
47
+ config = YAML.load(File.read('VERSION.yml'))
48
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "dm-s3 #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
58
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
data/dm-s3.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dm-s3}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Roberto Thais"]
9
+ s.date = %q{2009-06-26}
10
+ s.email = %q{roberto.n.thais@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "dm-s3.gemspec",
23
+ "lib/dm-s3.rb",
24
+ "test/dm-s3_test.rb",
25
+ "test/test_helper.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/rpbertp13/dm-s3}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.4}
31
+ s.summary = %q{TODO}
32
+ s.test_files = [
33
+ "test/dm-s3_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<aws-s3>, [">= 0.6.2"])
43
+ s.add_runtime_dependency(%q<dm-core>, [">= 0.9.11"])
44
+ else
45
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
46
+ s.add_dependency(%q<dm-core>, [">= 0.9.11"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
50
+ s.add_dependency(%q<dm-core>, [">= 0.9.11"])
51
+ end
52
+ end
data/lib/dm-s3.rb ADDED
@@ -0,0 +1,109 @@
1
+ require 'dm-core'
2
+ require 'aws/s3'
3
+
4
+ module DataMapper
5
+ module S3
6
+
7
+ class BaseBucketConnector
8
+ def initialize
9
+ @s3 = AWS::S3::S3Object
10
+ end
11
+
12
+ def get_s3_object(instance)
13
+ @s3.find(instance.s3_key)
14
+ end
15
+
16
+ def store(instance, file, options)
17
+ @s3.store(instance.s3_key, file, options)
18
+ end
19
+ end
20
+
21
+ class InstanceBucketConnector < BaseBucketConnector
22
+ def get_s3_object(instance)
23
+ s3(instance)
24
+ super
25
+ end
26
+
27
+ def store(instance, file, options)
28
+ s3(instance)
29
+ super
30
+ end
31
+
32
+ def s3(instance)
33
+ @s3.set_current_bucket_to instance.s3_bucket
34
+ end
35
+ end
36
+
37
+ class ClassBucketConnector < BaseBucketConnector
38
+ def initialize(klass, bucket_name)
39
+ @class = klass
40
+ @bucket_name = bucket_name
41
+ super()
42
+ end
43
+
44
+ def get_s3_object(instance)
45
+ self.s3
46
+ super
47
+ end
48
+
49
+ def store(instance, file, options)
50
+ s3
51
+ super
52
+ end
53
+
54
+ def bucket
55
+ AWS::S3::Bucket.find @bucket_name
56
+ end
57
+
58
+ def s3
59
+ @s3.set_current_bucket_to @bucket_name
60
+ @s3
61
+ end
62
+ end
63
+
64
+ module InstanceMethods
65
+ def s3
66
+ self.class.connector.get_s3_object(self)
67
+ end
68
+
69
+ def store_with(file, options = nil)
70
+ self.class.connector.store(self, file, options)
71
+ end
72
+
73
+ #Shortcut method for urls - defaults to unauthenticated
74
+ def url(options = {:authenticated => false})
75
+ s3.url(options)
76
+ end
77
+
78
+ [:value, :metadata, :about].each do |m|
79
+ send :define_method, m do
80
+ s3.send(m)
81
+ end
82
+ end
83
+ end
84
+
85
+ module ClassMethods
86
+ #Auto-add the properties in future version
87
+
88
+ attr_reader :connector
89
+
90
+ def has_s3_file_at(bucket_name)
91
+ @connector = ClassBucketConnector.new(self, bucket_name)
92
+ class << self
93
+ send :define_method, :s3 do
94
+ self.connector.s3
95
+ end
96
+ send :define_method, :bucket do
97
+ self.connector.bucket
98
+ end
99
+ end
100
+ end
101
+
102
+ def has_s3_file
103
+ @connector = InstanceBucketConnector.new
104
+ end
105
+ end
106
+ end
107
+ Resource.append_inclusions(S3::InstanceMethods)
108
+ Model.append_extensions(S3::ClassMethods)
109
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class DmS3Test < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dm-s3'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpbertp13-dm-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Thais
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-26 00:00:00 -07: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: dm-core
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.11
34
+ version:
35
+ description:
36
+ email: roberto.n.thais@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.yml
51
+ - dm-s3.gemspec
52
+ - lib/dm-s3.rb
53
+ - test/dm-s3_test.rb
54
+ - test/test_helper.rb
55
+ has_rdoc: false
56
+ homepage: http://github.com/rpbertp13/dm-s3
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: TODO
81
+ test_files:
82
+ - test/dm-s3_test.rb
83
+ - test/test_helper.rb