paperclip-s3 1.0.0rc1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -1,11 +1,6 @@
1
- h1. THIS IS NOT WORKING (YET)!
2
-
3
-
4
1
  h1. Paperclip S3 Storage
5
2
 
6
- This gem will force paperclip to store attachments on S3. It's great for "Heroku":http://heroku.com apps and thats basically why I wrote it.
7
-
8
- I was really lazy writing this over and over again, so I just gemed it.
3
+ This gem will force paperclip to store attachments on S3 if your application is in production. It's great for "Heroku":http://heroku.com apps.
9
4
 
10
5
  h1. Important Notes
11
6
 
@@ -13,6 +8,32 @@ If you're in fact using "Heroku":http://heroku.com, and you want the attachments
13
8
 
14
9
  A default, Heroku-working path is on by default, so you can just use it.
15
10
 
11
+ h1. How to Use
12
+
13
+ This gem will read your S3 credentials from the server's environment. You will need to provide a secret key, an access key and a bucket. (You can provide an *_s3_credentials_* hash options with *_access_key_id_* and *_secret_access_key_* instead.)
14
+
15
+ If you are using "Heroku":http://heroku.com, it's really easy to do this, just
16
+
17
+ <pre>
18
+ heroku config:add S3_BUCKET=your_bucket_name
19
+ heroku config:add S3_KEY=your_access_key
20
+ heroku config:add S3_SECRET=your_secret_key
21
+ </pre>
22
+
23
+ Ok, if you're really lazy, you can do that in one line:
24
+
25
+ <pre>
26
+ heroku config:add S3_BUCKET=your_bucket_name S3_KEY=your_access_key S3_SECRET=your_secret_key
27
+ </pre>
28
+
29
+ After you've done this, you can use paperclip normally. The gem just extends this methods and changes the options to force the S3 Storage. You can *even* use the same options (like path, default_style, etc.)
30
+
31
+
32
+
16
33
  h2. Contribute
17
34
 
18
- Feel free to fork, fix/patch/extend this. Everything is welcome.
35
+ Feel free to fork, fix/patch/extend this. Everything is welcome.
36
+
37
+ h3. TODO
38
+
39
+ * Clean the Railtie, specially the Rails.env part.
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "paperclip-s3")
data/lib/paperclip-s3.rb CHANGED
@@ -1,22 +1,28 @@
1
- require 'rails'
2
1
  require 'paperclip'
3
2
  require 'paperclip-s3/version'
4
3
  require 'paperclip-s3/railtie'
5
4
 
6
5
 
7
6
  module Paperclip
8
- module S3
7
+ module S3
8
+
9
+ # Use Paperclip::S3::Glue to keep the original gems style
10
+ module Glue
11
+ def self.included base
12
+ base.extend ClassMethods
13
+ end
14
+ end
15
+
9
16
  module ClassMethods
10
17
  # Extends the paperclips has_attached_file method
11
18
  # It will use S3 Storage. The credentials will be read from the environment
12
19
  def has_attached_file(name, options = {})
13
- ActiveRecord::Base.logger.error {"\n\n\n#################################### Hello from S3 Gem"}
14
20
  options[:storage] = :s3
15
- options[:path] = "/:class-:attachment/:id/:style-:basename.:extension"
16
- options[:bucket] = ENV["S3_BUCKET"]
17
- options[:s3_credentials] = {
18
- :access_key_id => ENV['S3_KEY'],
19
- :secret_access_key => ENV['S3_SECRET']
21
+ options[:path] ||= "/:class-:attachment/:id/:style-:basename.:extension"
22
+ options[:bucket] ||= ENV["S3_BUCKET"]
23
+ options[:s3_credentials] ||= {
24
+ :access_key_id => ENV['S3_KEY'],
25
+ :secret_access_key => ENV['S3_SECRET']
20
26
  }
21
27
  super(name, options)
22
28
  end
@@ -1,6 +1,7 @@
1
1
  module Paperclip
2
2
  module S3
3
3
  if defined? Rails::Railtie # Don't break rails 2.x
4
+ require 'rails'
4
5
  class Railtie < Rails::Railtie
5
6
  initializer 'paperclip.force_s3_attachment_on_production' do
6
7
  ActiveSupport.on_load :active_record do
@@ -12,7 +13,10 @@ module Paperclip
12
13
 
13
14
  class Railtie
14
15
  def self.insert
15
- ActiveRecord::Base.send(:extend, Paperclip::S3::ClassMethods)
16
+ if (defined?(Rails.env) && Rails.env && Rails.env.production?) or
17
+ (defined?(RAILS_ENV) && RAILS_ENV && RAILS_ENV =~ /production/)
18
+ ActiveRecord::Base.send(:include, Paperclip::S3::Glue)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module S3
3
- VERSION = "1.0.0rc1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'paperclip-s3/railtie'
2
+ Paperclip::S3::Railtie.insert
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-s3
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 5
5
- version: 1.0.0rc1
4
+ prerelease:
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Nicol\xC3\xA1s Hock Isaza"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-14 00:00:00 -05:00
13
+ date: 2011-06-15 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -49,10 +49,12 @@ files:
49
49
  - Gemfile
50
50
  - README.textile
51
51
  - Rakefile
52
+ - init.rb
52
53
  - lib/paperclip-s3.rb
53
54
  - lib/paperclip-s3/railtie.rb
54
55
  - lib/paperclip-s3/version.rb
55
56
  - paperclip-s3.gemspec
57
+ - rails/init.rb
56
58
  has_rdoc: true
57
59
  homepage: ""
58
60
  licenses: []
@@ -71,9 +73,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
73
  required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  none: false
73
75
  requirements:
74
- - - ">"
76
+ - - ">="
75
77
  - !ruby/object:Gem::Version
76
- version: 1.3.1
78
+ version: "0"
77
79
  requirements: []
78
80
 
79
81
  rubyforge_project: paperclip-s3