paperclip 5.0.0.beta1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -4
  3. data/NEWS +22 -1
  4. data/README.md +49 -45
  5. data/UPGRADING +3 -0
  6. data/features/migration.feature +0 -24
  7. data/features/step_definitions/rails_steps.rb +0 -6
  8. data/features/step_definitions/s3_steps.rb +2 -6
  9. data/gemfiles/5.0.awsv2.0.gemfile +1 -1
  10. data/gemfiles/5.0.awsv2.1.gemfile +1 -1
  11. data/gemfiles/5.0.awsv2.gemfile +1 -6
  12. data/lib/paperclip/attachment.rb +3 -2
  13. data/lib/paperclip/content_type_detector.rb +3 -2
  14. data/lib/paperclip/errors.rb +3 -1
  15. data/lib/paperclip/helpers.rb +14 -10
  16. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  17. data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
  18. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  19. data/lib/paperclip/schema.rb +1 -6
  20. data/lib/paperclip/storage/fog.rb +9 -6
  21. data/lib/paperclip/storage/s3.rb +16 -38
  22. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  23. data/lib/paperclip/version.rb +3 -1
  24. data/lib/paperclip.rb +2 -1
  25. data/lib/tasks/paperclip.rake +1 -1
  26. data/paperclip.gemspec +1 -2
  27. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  28. data/spec/paperclip/attachment_spec.rb +1 -4
  29. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
  30. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
  31. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  32. data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
  33. data/spec/paperclip/paperclip_spec.rb +3 -1
  34. data/spec/paperclip/storage/fog_spec.rb +10 -0
  35. data/spec/paperclip/storage/s3_spec.rb +92 -215
  36. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  37. data/spec/paperclip/validators_spec.rb +1 -0
  38. metadata +10 -8
  39. data/cucumber/paperclip_steps.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a699912c4b56d87a1b16846ed1b9772f6149aeeb
4
- data.tar.gz: f975845257fa910032dfc7b52913cd2b17917079
3
+ metadata.gz: 4787def2cfada09ed3791a17a356d403c289df8a
4
+ data.tar.gz: fa4e3a08de8f08483299905ea9ed65e9246bcf9f
5
5
  SHA512:
6
- metadata.gz: 46c3a1935badc5820ca134933317f37bd284b2d01ff755b52250f5105e27aa562e3bfb9d20f1aa95c44994b0de477c1feec81d24b53be3e5e9e1852bd45d5448
7
- data.tar.gz: 43b0e540a847140ba445040281be26d23308f9afe204d0bd5911fa6b245cd7cbb079e987460effe2784d94f7019313cbb5fd662fe9c1dc09160bcde9cb28db13
6
+ metadata.gz: 6c34f90ee3cce719d4915eab1703bb0825584e2361230402bc705e6d5ac0e98e5cc5dc524380d5bed415c38e208604156223f3315044b76ef98b11ddd8cb1817
7
+ data.tar.gz: b1b9a56925bb9d9c35725a500f241deab6631c9b1142815dfd1d93104a99de12aa74ae68f4a415599fb3f966ce1b189577e977a1c2d24d521b5f35e592cc76ae
data/CONTRIBUTING.md CHANGED
@@ -10,16 +10,22 @@ Here's a quick guide for contributing:
10
10
 
11
11
  1. Fork the repo.
12
12
 
13
- 2. Run the tests. We only take pull requests with passing tests, and it's great
13
+ 1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
14
+ (./README.md#image-processor) of the README.
15
+
16
+ 1. Run the tests. We only take pull requests with passing tests, and it's great
14
17
  to know that you have a clean slate: `bundle && bundle exec rake`
15
18
 
16
- 3. Add a test for your change. Only refactoring and documentation changes
19
+ 1. Add a test for your change. Only refactoring and documentation changes
17
20
  require no new tests. If you are adding functionality or fixing a bug, we need
18
21
  a test!
19
22
 
20
- 4. Make the test pass.
23
+ 1. Make the test pass.
24
+
25
+ 1. Mention how your changes affect the project to other developers and users in
26
+ the `NEWS.md` file.
21
27
 
22
- 5. Push to your fork and submit a pull request.
28
+ 1. Push to your fork and submit a pull request.
23
29
 
24
30
  At this point you're waiting on us. We like to at least comment on, if not
25
31
  accept, pull requests within seven business days (most of the work on Paperclip
data/NEWS CHANGED
@@ -1,5 +1,26 @@
1
- 5.0.0.beta1
1
+ master:
2
2
 
3
+ 5.0.0 (2016-07-01):
4
+
5
+ * Improvement: Add `read_timeout` configuration for URI Adapter download_content method.
6
+ * README adjustments for Ruby beginners (add links, elucidate model in Quick Start)
7
+ * Bugfix: Now it's possible to save images from URLs with special characters [#1932]
8
+ * Bugfix: Return false when file to copy is not present in cloud storage [#2173]
9
+ * Automatically close file while checking mime type [#2016]
10
+ * Add `read_timeout` option to `UriAdapter#download_content` method [#2232]
11
+ * Fix a nil error in content type validation matcher [#1910]
12
+ * Documentation improvements
13
+
14
+ 5.0.0.beta2 (2016-04-01):
15
+
16
+ * Bugfix: Dynamic fog directory option is now respected
17
+ * Bugfix: Fixes cocaine duplicated paths [#2169]
18
+ * Removal of dead code (older versions of Rails and AWS SDK)
19
+ * README adjustments
20
+
21
+ 5.0.0.beta1 (2016-03-13):
22
+
23
+ * Bug Fix: megabytes of mime-types info in logs when a spoofed media type is detected.
3
24
  * Drop support to end-of-life'd ruby 2.0.
4
25
  * Drop support for end-of-life'd Rails 3.2 and 4.1
5
26
  * Drop support for AWS v1
data/README.md CHANGED
@@ -14,6 +14,10 @@ https://github.com/thoughtbot/paperclip/releases
14
14
  [![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.svg)](http://inch-ci.org/github/thoughtbot/paperclip)
15
15
  [![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
16
16
 
17
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
18
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
19
+
20
+
17
21
  - [Requirements](#requirements)
18
22
  - [Ruby and Rails](#ruby-and-rails)
19
23
  - [Image Processor](#image-processor)
@@ -25,7 +29,7 @@ https://github.com/thoughtbot/paperclip/releases
25
29
  - [Edit and New Views](#edit-and-new-views)
26
30
  - [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
27
31
  - [Controller](#controller)
28
- - [Show View](#show-view)
32
+ - [View Helpers](#view-helpers)
29
33
  - [Deleting an Attachment](#deleting-an-attachment)
30
34
  - [Usage](#usage)
31
35
  - [Validations](#validations)
@@ -45,15 +49,18 @@ https://github.com/thoughtbot/paperclip/releases
45
49
  - [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
46
50
  - [Custom Attachment Processors](#custom-attachment-processors)
47
51
  - [Dynamic Configuration](#dynamic-configuration)
48
- - [Dynamic Styles](#dynamic-styles)
49
- - [Dynamic Processors](#dynamic-processors)
52
+ - [Dynamic Styles:](#dynamic-styles)
53
+ - [Dynamic Processors:](#dynamic-processors)
50
54
  - [Logging](#logging)
51
55
  - [Deployment](#deployment)
56
+ - [Attachment Styles](#attachment-styles)
52
57
  - [Testing](#testing)
53
58
  - [Contributing](#contributing)
54
59
  - [License](#license)
55
60
  - [About thoughtbot](#about-thoughtbot)
56
61
 
62
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
63
+
57
64
  Paperclip is intended as an easy file attachment library for ActiveRecord. The
58
65
  intent behind it was to keep setup as easy as possible and to treat files as
59
66
  much like other attributes as possible. This means they aren't saved to their
@@ -97,7 +104,7 @@ In development mode, you might add this line to `config/environments/development
97
104
  Paperclip.options[:command_path] = "/usr/local/bin/"
98
105
  ```
99
106
 
100
- If you're on Mac OS X, you'll want to run the following with Homebrew:
107
+ If you're on Mac OS X, you'll want to run the following with [Homebrew] (http://www.brew.sh):
101
108
 
102
109
  brew install imagemagick
103
110
 
@@ -159,7 +166,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
159
166
  Include the gem in your Gemfile:
160
167
 
161
168
  ```ruby
162
- gem "paperclip", "~> 5.0"
169
+ gem "paperclip", "~> 5.0.0"
163
170
  ```
164
171
 
165
172
  Or, if you want to get the latest, you can get master from the main paperclip repository:
@@ -189,18 +196,6 @@ Quick Start
189
196
 
190
197
  ### Models
191
198
 
192
- **Rails 3**
193
-
194
- ```ruby
195
- class User < ActiveRecord::Base
196
- attr_accessible :avatar
197
- has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
198
- validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
199
- end
200
- ```
201
-
202
- **Rails 4**
203
-
204
199
  ```ruby
205
200
  class User < ActiveRecord::Base
206
201
  has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
@@ -232,7 +227,8 @@ end
232
227
  <% end %>
233
228
  ```
234
229
 
235
- ### Edit and New Views with Simple Form
230
+ ### Edit and New Views with [Simple Form](https://github.com/plataformatec/simple_form)
231
+
236
232
  ```erb
237
233
  <%= simple_form_for @user, url: users_path do |form| %>
238
234
  <%= form.input :avatar, as: :file %>
@@ -241,16 +237,6 @@ end
241
237
 
242
238
  ### Controller
243
239
 
244
- **Rails 3**
245
-
246
- ```ruby
247
- def create
248
- @user = User.create( params[:user] )
249
- end
250
- ```
251
-
252
- **Rails 4**
253
-
254
240
  ```ruby
255
241
  def create
256
242
  @user = User.create( user_params )
@@ -266,7 +252,7 @@ def user_params
266
252
  end
267
253
  ```
268
254
 
269
- ### Show View
255
+ ### View Helpers
270
256
 
271
257
  ```erb
272
258
  <%= image_tag @user.avatar.url %>
@@ -451,14 +437,13 @@ will not cause errors to be raised.
451
437
 
452
438
  This can sometimes cause false validation errors in applications that use custom
453
439
  file extensions. In these cases you may wish to add your custom extension to the
454
- list of file extensions allowed for your MIME type configured by the `mime-types`
455
- gem:
440
+ list of content type mappings by creating `config/initializers/paperclip.rb`:
456
441
 
457
442
  ```ruby
458
443
  # Allow ".foo" as an extension for files with the MIME type "text/plain".
459
- text_plain = MIME::Types["text/plain"].first
460
- text_plain.extensions << "foo"
461
- MIME::Types.index_extensions text_plain
444
+ Paperclip.options[:content_type_mappings] = {
445
+ foo: %w(text/plain)
446
+ }
462
447
  ```
463
448
 
464
449
  ---
@@ -582,8 +567,8 @@ The files that are assigned as attachments are, by default, placed in the
582
567
  directory specified by the `:path` option to `has_attached_file`. By default, this
583
568
  location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
584
569
  This location was chosen because, on standard Capistrano deployments, the
585
- `public/system` directory is symlinked to the app's shared directory, meaning it
586
- will survive between deployments. For example, using that `:path`, you may have a
570
+ `public/system` directory can be symlinked to the app's shared directory, meaning it
571
+ survives between deployments. For example, using that `:path`, you may have a
587
572
  file at
588
573
 
589
574
  /data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png
@@ -595,16 +580,13 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
595
580
  the `aws-sdk` gem in your Gemfile:
596
581
 
597
582
  ```ruby
598
- gem 'aws-sdk', '>= 2.0.0' # If using paperclip `master` (upcoming v5.0)
583
+ gem 'aws-sdk', '>= 2.0.34'
599
584
  ```
600
585
 
601
586
  And then you can specify using S3 from `has_attached_file`.
602
587
  You can find more information about configuring and using S3 storage in
603
588
  [the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
604
589
 
605
- _**NOTE**: If upgrading aws-sdk from v1.x to v2.x, be sure to read the
606
- [UPGRADING guide](https://github.com/thoughtbot/paperclip/blob/master/UPGRADING)._
607
-
608
590
  Files on the local filesystem (and in the Rails app's public directory) will be
609
591
  available to the internet at large. If you require access control, it's
610
592
  possible to place your files in a different location. You will need to change
@@ -634,7 +616,8 @@ has_attached_file :scan, styles: { text: { quality: :better } },
634
616
 
635
617
  This would load the hypothetical class Paperclip::Ocr, which would have the
636
618
  hash "{ quality: :better }" passed to it along with the uploaded file. For
637
- more information about defining processors, see Paperclip::Processor.
619
+ more information about defining processors, see
620
+ [Paperclip::Processor](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb).
638
621
 
639
622
  The default processor is Paperclip::Thumbnail. For backward compatibility
640
623
  reasons, you can pass a single geometry string or an array containing a
@@ -847,6 +830,16 @@ More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperc
847
830
  Deployment
848
831
  ----------
849
832
 
833
+ To make Capistrano symlink the `public/system` directory so that attachments
834
+ survive new deployments, set the `linked_dirs` option in your `config/deploy.rb`
835
+ file:
836
+
837
+ ```ruby
838
+ set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
839
+ ```
840
+
841
+ ### Attachment Styles
842
+
850
843
  Paperclip is aware of new attachment styles you have added in previous deploys. The only thing you should do after each deployment is to call
851
844
  `rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
852
845
  by default. You can change it by:
@@ -858,9 +851,9 @@ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachment
858
851
  Here is an example for Capistrano:
859
852
 
860
853
  ```ruby
861
- namespace :deploy do
854
+ namespace :paperclip do
862
855
  desc "build missing paperclip styles"
863
- task :build_missing_paperclip_styles do
856
+ task :build_missing_styles do
864
857
  on roles(:app) do
865
858
  within release_path do
866
859
  with rails_env: fetch(:rails_env) do
@@ -871,7 +864,7 @@ namespace :deploy do
871
864
  end
872
865
  end
873
866
 
874
- after("deploy:compile_assets", "deploy:build_missing_paperclip_styles")
867
+ after("deploy:compile_assets", "paperclip:build_missing_styles")
875
868
  ```
876
869
 
877
870
  Now you don't have to remember to refresh thumbnails in production every time you add a new style.
@@ -954,6 +947,17 @@ config.after(:suite) do
954
947
  FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
955
948
  end
956
949
  ```
950
+
951
+ **Example of test configuration with Factory Girl**
952
+
953
+
954
+ ```ruby
955
+ FactoryGirl.define do
956
+ factory :user do
957
+ avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
958
+ end
959
+ end
960
+ ```
957
961
  ---
958
962
 
959
963
  Contributing
@@ -969,7 +973,7 @@ guidelines:
969
973
  about writing tests for paperclip, please open a
970
974
  [GitHub issue](https://github.com/thoughtbot/paperclip/issues/new).
971
975
 
972
- Please see `CONTRIBUTING.md` for more details on contributing and running test.
976
+ Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
973
977
 
974
978
  Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
975
979
 
data/UPGRADING CHANGED
@@ -12,3 +12,6 @@ changes:
12
12
  note that the format of the permissions changed from using an underscore to
13
13
  using a hyphen. For example, `:public_read` needs to be changed to
14
14
  `public-read`.
15
+
16
+ For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
17
+ http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
@@ -68,27 +68,3 @@ Feature: Migration
68
68
 
69
69
  When I rollback a migration
70
70
  Then I should not have attachment columns for "avatar"
71
-
72
- Scenario: Rails 3.2 change method
73
- Given I am using Rails newer than 3.1
74
- When I write to "db/migrate/01_create_users.rb" with:
75
- """
76
- class CreateUsers < ActiveRecord::Migration
77
- def self.up
78
- create_table :users
79
- end
80
- end
81
- """
82
- When I write to "db/migrate/02_add_attachment_to_users.rb" with:
83
- """
84
- class AddAttachmentToUsers < ActiveRecord::Migration
85
- def change
86
- add_attachment :users, :avatar
87
- end
88
- end
89
- """
90
- And I run a migration
91
- Then I should have attachment columns for "avatar"
92
-
93
- When I rollback a migration
94
- Then I should not have attachment columns for "avatar"
@@ -190,12 +190,6 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
190
190
  comment_out_gem_in_gemfile gemname
191
191
  end
192
192
 
193
- Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
194
- if framework_version < version
195
- pending "Not supported in Rails < #{version}"
196
- end
197
- end
198
-
199
193
  Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
200
194
  filename = "#{directory}/#{processor}.rb"
201
195
  cd(".") do
@@ -1,15 +1,11 @@
1
1
  When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
2
2
  definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
3
- path = if defined?(::AWS)
4
- "https://paperclip.s3.amazonaws.com#{definition[:path]}"
5
- else
6
- "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
7
- end
3
+ path = "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
8
4
  path.gsub!(':filename', File.basename(file_path))
9
5
  path.gsub!(/:([^\/\.]+)/) do |match|
10
6
  "([^\/\.]+)"
11
7
  end
12
- FakeWeb.register_uri(:put, Regexp.new(path), :body => defined?(::AWS) ? "OK" : "<xml></xml>")
8
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "<xml></xml>")
13
9
  step "I attach the file \"#{file_path}\" to \"#{field}\""
14
10
  end
15
11
 
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
6
  gem "pry"
7
- gem "rails", "5.0.0.beta3"
7
+ gem "rails", "5.0.0"
8
8
  gem "aws-sdk", "~> 2.0.0"
9
9
 
10
10
  group :development, :test do
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
6
  gem "pry"
7
- gem "rails", "5.0.0.beta3"
7
+ gem "rails", "5.0.0"
8
8
  gem "aws-sdk", "~> 2.1.0"
9
9
 
10
10
  group :development, :test do
@@ -8,12 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
8
  gem "rubysl", :platforms => :rbx
9
9
  gem "racc", :platforms => :rbx
10
10
  gem "pry"
11
- gem "rails", :github => "rails/rails"
12
- gem "sprockets-rails", :github => "rails/sprockets-rails"
13
- gem "sprockets", :github => "rails/sprockets"
14
- gem "sass-rails", :github => "rails/sass-rails"
15
- gem "arel", :github => "rails/arel"
16
- gem "rack", :github => "rack/rack"
11
+ gem "rails", "~> 5.0.0"
17
12
  gem "aws-sdk", "~> 2.0"
18
13
 
19
14
  group :development, :test do
@@ -50,7 +50,8 @@ module Paperclip
50
50
  # +url+ - a relative URL of the attachment. This is interpolated using +interpolator+
51
51
  # +path+ - where on the filesystem to store the attachment. This is interpolated using +interpolator+
52
52
  # +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
53
- # +only_process+ - style args to be run through the post-processor. This defaults to the empty list
53
+ # +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
54
+ # a special case that indicates all styles should be processed)
54
55
  # +default_url+ - a URL for the missing image
55
56
  # +default_style+ - the style to use when an argument is not specified e.g. #url, #path
56
57
  # +storage+ - the storage mechanism. Defaults to :filesystem
@@ -348,7 +349,7 @@ module Paperclip
348
349
 
349
350
  # Returns true if a file has been assigned.
350
351
  def file?
351
- !original_filename.blank?
352
+ original_filename.present?
352
353
  end
353
354
 
354
355
  alias :present? :file?
@@ -67,8 +67,9 @@ module Paperclip
67
67
  end
68
68
 
69
69
  def type_from_mime_magic
70
- @type_from_mime_magic ||=
71
- MimeMagic.by_magic(File.open(@filepath)).try(:type)
70
+ @type_from_mime_magic ||= File.open(@filepath) do |file|
71
+ MimeMagic.by_magic(file).try(:type)
72
+ end
72
73
  end
73
74
 
74
75
  def type_from_file_command
@@ -19,7 +19,9 @@ module Paperclip
19
19
  end
20
20
 
21
21
  # Will be thrown when ImageMagic cannot determine the uploaded file's
22
- # metadata, usually this would mean the file is not an image.
22
+ # metadata, usually this would mean the file is not an image. If you are
23
+ # consistently receiving this error on PDFs make sure that you have
24
+ # installed Ghostscript.
23
25
  class NotIdentifiedByImageMagickError < Paperclip::Error
24
26
  end
25
27
 
@@ -8,23 +8,27 @@ module Paperclip
8
8
  Paperclip::Interpolations[key] = block
9
9
  end
10
10
 
11
- # The run method takes the name of a binary to run, the arguments to that binary
12
- # and some options:
11
+ # The run method takes the name of a binary to run, the arguments
12
+ # to that binary, the values to interpolate and some local options.
13
13
  #
14
- # :command_path -> A $PATH-like variable that defines where to look for the binary
15
- # on the filesystem. Colon-separated, just like $PATH.
14
+ # :cmd -> The name of a binary to run.
16
15
  #
17
- # :expected_outcodes -> An array of integers that defines the expected exit codes
18
- # of the binary. Defaults to [0].
16
+ # :arguments -> The command line arguments to that binary.
19
17
  #
20
- # :log_command -> Log the command being run when set to true (defaults to true).
21
- # This will only log if logging in general is set to true as well.
18
+ # :interpolation_values -> Values to be interpolated into the arguments.
22
19
  #
23
- # :swallow_stderr -> Set to true if you don't care what happens on STDERR.
20
+ # :local_options -> The options to be used by Cocain::CommandLine.
21
+ # These could be: runner
22
+ # logger
23
+ # swallow_stderr
24
+ # expected_outcodes
25
+ # environment
26
+ # runner_options
24
27
  #
25
28
  def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
26
29
  command_path = options[:command_path]
27
- Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
30
+ cocaine_path_array = Cocaine::CommandLine.path.try(:split, Cocaine::OS.path_separator)
31
+ Cocaine::CommandLine.path = [cocaine_path_array, command_path].flatten.compact.uniq
28
32
  if logging? && (options[:log_command] || local_options[:log_command])
29
33
  local_options = local_options.merge(:logger => logger)
30
34
  end
@@ -4,7 +4,7 @@ module Paperclip
4
4
  REGEXP = /\Ahttps?:\/\//
5
5
 
6
6
  def initialize(target)
7
- super(URI(target))
7
+ super(URI(URI.escape(target)))
8
8
  end
9
9
 
10
10
  end
@@ -14,7 +14,9 @@ module Paperclip
14
14
  private
15
15
 
16
16
  def download_content
17
- open(@target)
17
+ options = { read_timeout: Paperclip.options[:read_timeout] }.compact
18
+
19
+ open(@target, **options)
18
20
  end
19
21
 
20
22
  def cache_current_values
@@ -40,9 +40,9 @@ module Paperclip
40
40
 
41
41
  def failure_message
42
42
  "#{expected_attachment}\n".tap do |message|
43
- message << accepted_types_and_failures
43
+ message << accepted_types_and_failures.to_s
44
44
  message << "\n\n" if @allowed_types.present? && @rejected_types.present?
45
- message << rejected_types_and_failures
45
+ message << rejected_types_and_failures.to_s
46
46
  end
47
47
  end
48
48
 
@@ -55,7 +55,7 @@ module Paperclip
55
55
  def accepted_types_and_failures
56
56
  if @allowed_types.present?
57
57
  "Accept content types: #{@allowed_types.join(", ")}\n".tap do |message|
58
- if @missing_allowed_types.any?
58
+ if @missing_allowed_types.present?
59
59
  message << " #{@missing_allowed_types.join(", ")} were rejected."
60
60
  else
61
61
  message << " All were accepted successfully."
@@ -66,7 +66,7 @@ module Paperclip
66
66
  def rejected_types_and_failures
67
67
  if @rejected_types.present?
68
68
  "Reject content types: #{@rejected_types.join(", ")}\n".tap do |message|
69
- if @missing_rejected_types.any?
69
+ if @missing_rejected_types.present?
70
70
  message << " #{@missing_rejected_types.join(", ")} were accepted."
71
71
  else
72
72
  message << " All were rejected successfully."
@@ -12,10 +12,7 @@ module Paperclip
12
12
  ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
13
13
  ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
14
14
  ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
15
-
16
- if defined?(ActiveRecord::Migration::CommandRecorder) # Rails 3.1+
17
- ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
18
- end
15
+ ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
19
16
  end
20
17
 
21
18
  module Statements
@@ -35,8 +32,6 @@ module Paperclip
35
32
  def remove_attachment(table_name, *attachment_names)
36
33
  raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty?
37
34
 
38
- options = attachment_names.extract_options!
39
-
40
35
  attachment_names.each do |attachment_name|
41
36
  COLUMNS.keys.each do |column_name|
42
37
  remove_column(table_name, "#{attachment_name}_#{column_name}")
@@ -170,6 +170,7 @@ module Paperclip
170
170
  log("copying #{path(style)} to local file #{local_dest_path}")
171
171
  ::File.open(local_dest_path, 'wb') do |local_file|
172
172
  file = directory.files.get(path(style))
173
+ return false unless file
173
174
  local_file.write(file.body)
174
175
  end
175
176
  rescue ::Fog::Errors::Error => e
@@ -195,10 +196,10 @@ module Paperclip
195
196
  end
196
197
 
197
198
  def host_name_for_directory
198
- if @options[:fog_directory].to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
199
- "#{@options[:fog_directory]}.s3.amazonaws.com"
199
+ if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
200
+ "#{directory_name}.s3.amazonaws.com"
200
201
  else
201
- "s3.amazonaws.com/#{@options[:fog_directory]}"
202
+ "s3.amazonaws.com/#{directory_name}"
202
203
  end
203
204
  end
204
205
 
@@ -224,13 +225,15 @@ module Paperclip
224
225
  end
225
226
 
226
227
  def directory
227
- dir = if @options[:fog_directory].respond_to?(:call)
228
+ @directory ||= connection.directories.new(key: directory_name)
229
+ end
230
+
231
+ def directory_name
232
+ if @options[:fog_directory].respond_to?(:call)
228
233
  @options[:fog_directory].call(self)
229
234
  else
230
235
  @options[:fog_directory]
231
236
  end
232
-
233
- @directory ||= connection.directories.new(:key => dir)
234
237
  end
235
238
 
236
239
  def scheme