s3asy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/s3_object_proxy.rb
4
+ lib/s3asy.rb
5
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = S3asy
2
+
3
+ Rails gem for associating an s3 object with an active record model
4
+
5
+ == Install
6
+
7
+ gem install robertoles-s3asy --source http://gems.github.com
8
+
9
+ == Usage
10
+
11
+ You want to create an active record model 'product' which has an attribute 'image' which is an s3 object. First create a migration for your model and specify a string column for the image attribute followed by _name...
12
+
13
+ class CreateProducts < ActiveRecord::Migration
14
+ def self.up
15
+ create_table :products do |t|
16
+ t.string :image_name
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :products
24
+ end
25
+ end
26
+
27
+
28
+ Now you will need to specify your s3 credentials, to do this add the file /config/amazon_s3.yml
29
+
30
+ test:
31
+ access_key_id: your_access_key_id
32
+ secret_access_key: your_secret_access_key
33
+
34
+
35
+ Finally create the association in your model, specifying the bucket on s3 the object is stored in...
36
+
37
+ class Product < ActiveRecord::Base
38
+ has_s3object :image, :bucket => 'bucket'
39
+ end
40
+
41
+
42
+ == License
43
+
44
+ Copyright (c) 2010 Robert Oles
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ "Software"), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
60
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
61
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
62
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
63
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+ require 'echoe'
5
+
6
+ Echoe.new('s3asy', '0.1.0') do |p|
7
+ p.description = "Associate an s3 object to an active record model"
8
+ p.url = "http://github.com/robertoles/s3asy"
9
+ p.author = "Robert Oles"
10
+ p.email = "robertoles@me.com"
11
+ p.ignore_pattern = ["tmp/*", "script/*", "spec/*", "cucumber/*"]
12
+ p.development_dependencies = ['aws-s3']
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
16
+
17
+ Spec::Rake::SpecTask.new('spec') do |t|
18
+ t.spec_opts = ["-c"]
19
+ t.spec_files = FileList['spec/**/*.rb']
20
+ end
@@ -0,0 +1,25 @@
1
+ require 'aws/s3'
2
+
3
+ class S3ObjectProxy
4
+ attr_reader :path
5
+ attr_reader :bucket
6
+
7
+ def initialize(options = {})
8
+ @path = options[:path]
9
+ @bucket = options[:bucket]
10
+ initialize_s3(options)
11
+ end
12
+
13
+ def initialize_s3(options)
14
+ s3_config_path = options[:config_path] || (RAILS_ROOT + '/config/amazon_s3.yml')
15
+ s3_config = YAML.load_file(s3_config_path)[RAILS_ENV].symbolize_keys
16
+ AWS::S3::Base.establish_connection!(
17
+ :access_key_id => s3_config[:access_key_id],
18
+ :secret_access_key => s3_config[:secret_access_key]
19
+ )
20
+ end
21
+
22
+ def url
23
+ AWS::S3::S3Object.url_for(path, bucket, :authenticated => false)
24
+ end
25
+ end
data/lib/s3asy.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 's3_object_proxy'
2
+
3
+ module S3asy
4
+ class << self
5
+ def included base
6
+ base.extend ClassMethods
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def has_s3object name, options = {}
12
+ define_method name do |*args|
13
+ S3ObjectProxy.new(options.merge(:path => self.send(:"#{name}_name")))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ if Object.const_defined?("ActiveRecord")
20
+ ActiveRecord::Base.send(:include, S3asy)
21
+ end
data/s3asy.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{s3asy}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Robert Oles"]
9
+ s.date = %q{2010-02-04}
10
+ s.description = %q{Associate an s3 object to an active record model}
11
+ s.email = %q{robertoles@me.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/s3_object_proxy.rb", "lib/s3asy.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/s3_object_proxy.rb", "lib/s3asy.rb", "Manifest", "s3asy.gemspec"]
14
+ s.homepage = %q{http://github.com/robertoles/s3asy}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "S3asy", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{s3asy}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Associate an s3 object to an active record model}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<aws-s3>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<aws-s3>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<aws-s3>, [">= 0"])
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3asy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Oles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-04 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: aws-s3
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Associate an s3 object to an active record model
26
+ email: robertoles@me.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - lib/s3_object_proxy.rb
34
+ - lib/s3asy.rb
35
+ files:
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/s3_object_proxy.rb
39
+ - lib/s3asy.rb
40
+ - Manifest
41
+ - s3asy.gemspec
42
+ has_rdoc: true
43
+ homepage: http://github.com/robertoles/s3asy
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --title
51
+ - S3asy
52
+ - --main
53
+ - README.rdoc
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "1.2"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: s3asy
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Associate an s3 object to an active record model
75
+ test_files: []
76
+