paperclip_heroku 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,38 @@
1
- See documentation in <code>lib/paperclip/heroku.rb</code>.
1
+ # paperclip_heroku
2
2
 
3
- ## Specs
3
+ One-line S3 storage setup for Paperclip on Heroku.
4
4
 
5
- $ bundle install
6
- $ bundle exec rspec spec
5
+ Usage:
6
+
7
+ class User
8
+ has_attached_file :avatar, heroku: true
9
+ end
10
+
11
+ Using <code>heroku: true</code> configures Paperclip to use Amazon S3 on Heroku and the filesystem in development/testing.
12
+
13
+ ## Configuration
14
+
15
+ S3 storage config can be set on the command line, like this:
16
+
17
+ $ heroku config:add S3_BUCKET=my_bucket_name
18
+ $ heroku config:add S3_KEY=my_s3_access_key_id
19
+ $ heroku config:add S3_SECRET=my_s3_secret_access_key
20
+
21
+ You can also optionally set a S3_HOST_NAME to specify an endpoint for S3 requests: for example, if your S3 bucket is in the US West (Oregon) region, you should set S3_HOST_NAME to 's3-us-west-2.amazonaws.com'. If not set, this will default to s3.amazonaws.com. See [Amazon's docs][docs] for a list of valid hostnames/endpoints.
22
+
23
+ ## Environments
24
+
25
+ By default, paperclip_heroku assumes you want to use S3 in production. To override this:
26
+
27
+ $ heroku config:add S3_ENVIRONMENT=staging
28
+
29
+ Multiple environments are also supported:
30
+
31
+ $ heroku config:add S3_ENVIRONMENT=staging,production
32
+
33
+ ## Author
34
+
35
+ Developed by [James Wilding][jw]. Released under the MIT license.
36
+
37
+ [docs]: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
38
+ [jw]: http://jameswilding.net/
@@ -0,0 +1,3 @@
1
+ module PaperclipHeroku
2
+ VERSION = '0.4.0'
3
+ end
@@ -1 +1,52 @@
1
- require 'paperclip/heroku'
1
+ require 'paperclip'
2
+ require 'active_support/core_ext/module/aliasing'
3
+
4
+ module PaperclipHeroku
5
+ # Storage systems to use in development and production
6
+ DEVELOPMENT_STORAGE = :filesystem
7
+ PRODUCTION_STORAGE = :s3
8
+
9
+ # Default endpoint for S3 requests
10
+ DEFAULT_S3_HOST_NAME = 's3.amazonaws.com'
11
+
12
+ module ClassMethods
13
+ def has_attached_file_with_heroku(name, options = {})
14
+ if options[:heroku] == true
15
+ # Set per-environment options for Heroku/development
16
+ #
17
+ # :storage is a given. Other options are only set
18
+ # if the user hasn't provided values for them.
19
+ #
20
+ options[:storage] = environment_storage
21
+ options[:bucket] ||= ENV['S3_BUCKET']
22
+ options[:s3_host_name] ||= ENV['S3_HOST_NAME'] || PaperclipHeroku::DEFAULT_S3_HOST_NAME
23
+ options[:s3_credentials] ||= {
24
+ :access_key_id => ENV['S3_KEY'],
25
+ :secret_access_key => ENV['S3_SECRET']
26
+ }
27
+ end
28
+
29
+ has_attached_file_without_heroku(name, options)
30
+ end
31
+
32
+ private
33
+ def environment_storage
34
+ s3_environment? ? PaperclipHeroku::PRODUCTION_STORAGE : PaperclipHeroku::DEVELOPMENT_STORAGE
35
+ end
36
+
37
+ def s3_environment?
38
+ s3_environments.include?(Rails.env)
39
+ end
40
+
41
+ def s3_environments
42
+ (ENV['S3_ENVIRONMENT'] || 'production').split(',').map(&:strip)
43
+ end
44
+ end
45
+ end
46
+
47
+ module Paperclip
48
+ module ClassMethods
49
+ include PaperclipHeroku::ClassMethods
50
+ alias_method_chain :has_attached_file, :heroku
51
+ end
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip_heroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2013-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -97,8 +97,7 @@ executables: []
97
97
  extensions: []
98
98
  extra_rdoc_files: []
99
99
  files:
100
- - lib/paperclip/heroku/version.rb
101
- - lib/paperclip/heroku.rb
100
+ - lib/paperclip_heroku/version.rb
102
101
  - lib/paperclip_heroku.rb
103
102
  - README.md
104
103
  homepage: http://github.com/jameswilding/paperclip_heroku
@@ -1,15 +0,0 @@
1
- module Paperclip
2
- module Heroku
3
- module Version
4
- extend self
5
-
6
- MAJOR = 0
7
- MINOR = 2
8
- TINY = 1
9
-
10
- def to_s
11
- [MAJOR, MINOR, TINY].join('.')
12
- end
13
- end
14
- end
15
- end
@@ -1,80 +0,0 @@
1
- require 'paperclip'
2
- require 'active_support/core_ext/module/aliasing'
3
-
4
- module Paperclip
5
- module Heroku
6
- module ClassMethods
7
- # Default filesystem path at which to save attachments.
8
- DEFAULT_PATH = Paperclip::Attachment.default_options[:path]
9
-
10
- # Default endpoint for S3 requests
11
- DEFAULT_S3_HOST_NAME = 's3.amazonaws.com'
12
-
13
- # Adds a :heroku option to Paperclip's +has_attached_file+ method.
14
- #
15
- # class User
16
- # has_attached_file :avatar, heroku: true
17
- # end
18
- #
19
- # Using +heroku: true+ configures Paperclip to use Amazon S3 on Heroku
20
- # and the filesystem in development/testing.
21
- #
22
- # == Configuration
23
- #
24
- # S3 storage config can be set on the command line using +heroku config:add+, like this:
25
- #
26
- # $ heroku config:add S3_BUCKET=my_bucket_name
27
- # $ heroku config:add S3_KEY=my_s3_access_key_id
28
- # $ heroku config:add S3_SECRET=my_s3_secret_access_key
29
- #
30
- # You can also optionally set a S3_HOST_NAME to specify an endpoint for S3
31
- # requests: for example, if your S3 bucket is in the US West (Oregon) region,
32
- # you should set S3_HOST_NAME to 's3-us-west-2.amazonaws.com'. If not set,
33
- # this will default to s3.amazonaws.com.
34
- #
35
- # == Note
36
- #
37
- # Paperclip::Heroku assumes that Heroku is configured to run your
38
- # Rails app in the production environment.
39
- #
40
- def has_attached_file_with_heroku(name, options = {})
41
- if options[:heroku] == true
42
- # Set per-environment options for Heroku/development
43
- #
44
- # :storage is a given. Other options are only set
45
- # if the user hasn't provided values for them.
46
- #
47
- options[:storage] = environment_storage
48
- options[:path] ||= environment_path
49
- options[:url] ||= environment_url
50
- options[:bucket] ||= ENV['S3_BUCKET']
51
- options[:s3_host_name] ||= ENV['S3_HOST_NAME'] || DEFAULT_S3_HOST_NAME
52
- options[:s3_credentials] ||= {
53
- :access_key_id => ENV['S3_KEY'],
54
- :secret_access_key => ENV['S3_SECRET']
55
- }
56
- end
57
-
58
- has_attached_file_without_heroku(name, options)
59
- end
60
-
61
- private
62
- def environment_storage
63
- Rails.env.production? ? :s3 : :filesystem
64
- end
65
-
66
- def environment_path
67
- Rails.env.production? ? DEFAULT_PATH : ['public', DEFAULT_PATH].join
68
- end
69
-
70
- def environment_url
71
- Rails.env.production? ? ':s3_domain_url' : DEFAULT_PATH
72
- end
73
- end
74
- end
75
-
76
- module ClassMethods
77
- include Paperclip::Heroku::ClassMethods
78
- alias_method_chain :has_attached_file, :heroku
79
- end
80
- end