paperclip 4.2.4 → 4.3.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +1066 -0
  3. data/.rubocop.yml +1 -0
  4. data/.travis.yml +5 -3
  5. data/Appraisals +1 -6
  6. data/CONTRIBUTING.md +3 -3
  7. data/Gemfile +1 -0
  8. data/LICENSE +1 -1
  9. data/NEWS +14 -1
  10. data/README.md +137 -77
  11. data/RELEASING.md +17 -0
  12. data/Rakefile +1 -1
  13. data/features/basic_integration.feature +7 -4
  14. data/features/step_definitions/attachment_steps.rb +7 -1
  15. data/gemfiles/3.2.gemfile +2 -1
  16. data/gemfiles/4.1.gemfile +1 -0
  17. data/gemfiles/4.2.gemfile +2 -1
  18. data/lib/paperclip.rb +13 -3
  19. data/lib/paperclip/attachment.rb +3 -1
  20. data/lib/paperclip/attachment_registry.rb +1 -1
  21. data/lib/paperclip/content_type_detector.rb +26 -11
  22. data/lib/paperclip/file_command_content_type_detector.rb +6 -8
  23. data/lib/paperclip/glue.rb +1 -1
  24. data/lib/paperclip/has_attached_file.rb +2 -1
  25. data/lib/paperclip/interpolations.rb +1 -1
  26. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -0
  27. data/lib/paperclip/media_type_spoof_detector.rb +1 -1
  28. data/lib/paperclip/rails_environment.rb +25 -0
  29. data/lib/paperclip/storage/fog.rb +4 -4
  30. data/lib/paperclip/storage/s3.rb +2 -3
  31. data/lib/paperclip/thumbnail.rb +2 -3
  32. data/lib/paperclip/version.rb +1 -1
  33. data/lib/tasks/paperclip.rake +16 -0
  34. data/paperclip.gemspec +3 -4
  35. data/spec/paperclip/attachment_definitions_spec.rb +1 -1
  36. data/spec/paperclip/attachment_registry_spec.rb +56 -13
  37. data/spec/paperclip/attachment_spec.rb +57 -19
  38. data/spec/paperclip/content_type_detector_spec.rb +8 -1
  39. data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
  40. data/spec/paperclip/interpolations_spec.rb +2 -9
  41. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +2 -1
  42. data/spec/paperclip/io_adapters/file_adapter_spec.rb +4 -1
  43. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +4 -0
  44. data/spec/paperclip/media_type_spoof_detector_spec.rb +16 -2
  45. data/spec/paperclip/rails_environment_spec.rb +33 -0
  46. data/spec/paperclip/storage/fog_spec.rb +11 -2
  47. data/spec/paperclip/storage/s3_spec.rb +43 -25
  48. data/spec/paperclip/tempfile_factory_spec.rb +4 -0
  49. data/spec/paperclip/thumbnail_spec.rb +16 -0
  50. data/spec/paperclip/url_generator_spec.rb +1 -1
  51. data/spec/support/fake_model.rb +4 -0
  52. data/spec/support/fixtures/empty.xlsx +0 -0
  53. data/spec/support/matchers/have_column.rb +11 -2
  54. metadata +30 -12
  55. data/RUNNING_TESTS.md +0 -4
  56. data/gemfiles/4.0.gemfile +0 -19
  57. data/spec/support/mock_model.rb +0 -2
@@ -0,0 +1 @@
1
+ inherit_from: .hound.yml
@@ -1,23 +1,25 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - jruby-19mode
4
3
  - rbx-2
5
4
  - 2.0.0
6
5
  - 2.1.1
6
+ - 2.2.2
7
7
 
8
8
  install:
9
9
  - "travis_retry bundle install"
10
10
 
11
- before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
12
11
  script: "bundle exec rake clean spec cucumber"
13
12
 
14
13
  gemfile:
15
14
  - gemfiles/3.2.gemfile
16
- - gemfiles/4.0.gemfile
17
15
  - gemfiles/4.1.gemfile
16
+ - gemfiles/4.2.gemfile
18
17
 
19
18
  matrix:
20
19
  fast_finish: true
21
20
  allow_failures:
22
21
  - rvm: jruby-19mode
23
22
  - rvm: rbx-2
23
+
24
+ sudo: false
25
+ cache: bundler
data/Appraisals CHANGED
@@ -3,17 +3,12 @@ appraise "3.2" do
3
3
  gem "paperclip", :path => "../"
4
4
  end
5
5
 
6
- appraise "4.0" do
7
- gem "rails", "~> 4.0.0"
8
- gem "paperclip", :path => "../"
9
- end
10
-
11
6
  appraise "4.1" do
12
7
  gem "rails", "~> 4.1.0"
13
8
  gem "paperclip", :path => "../"
14
9
  end
15
10
 
16
11
  appraise "4.2" do
17
- gem "rails", "~> 4.2.0.rc2"
12
+ gem "rails", "~> 4.2.0"
18
13
  gem "paperclip", :path => "../"
19
14
  end
@@ -6,7 +6,7 @@ We love pull requests. Here's a quick guide:
6
6
  1. Fork the repo.
7
7
 
8
8
  2. Run the tests. We only take pull requests with passing tests, and it's great
9
- to know that you have a clean slate: `bundle && rake`
9
+ to know that you have a clean slate: `bundle && bundle exec rake`
10
10
 
11
11
  3. Add a test for your change. Only refactoring and documentation changes
12
12
  require no new tests. If you are adding functionality or fixing a bug, we need
@@ -43,14 +43,14 @@ will be asked to rewrite them before we'll accept.
43
43
  ### Bootstrapping your test suite:
44
44
 
45
45
  bundle install
46
- bundle exec rake appraisal:install
46
+ bundle exec appraisal install
47
47
 
48
48
  This will install all the required gems that requires to test against each
49
49
  version of Rails, which defined in `gemfiles/*.gemfile`.
50
50
 
51
51
  ### To run a full test suite:
52
52
 
53
- bundle exec rake
53
+ bundle exec appraisal rake
54
54
 
55
55
  This will run RSpec and Cucumber against all version of Rails
56
56
 
data/Gemfile CHANGED
@@ -17,4 +17,5 @@ gem 'pry'
17
17
  group :development, :test do
18
18
  gem 'mime-types', '~> 1.16'
19
19
  gem 'builder'
20
+ gem 'rubocop', require: false
20
21
  end
data/LICENSE CHANGED
@@ -3,7 +3,7 @@ LICENSE
3
3
 
4
4
  The MIT License
5
5
 
6
- Copyright (c) 2008-2014 Jon Yurek and thoughtbot, inc.
6
+ Copyright (c) 2008-2015 Jon Yurek and thoughtbot, inc.
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  of this software and associated documentation files (the "Software"), to deal
data/NEWS CHANGED
@@ -1,3 +1,16 @@
1
+ 4.3.0:
2
+
3
+ * Improvement: Update aws-sdk and cucumber gem versions.
4
+ * Improvement: Add `length` alias for `size` method in AbstractAdapter.
5
+ * Improvement: Removed some cruft
6
+ * Improvement: deep_merge! Attachment definitions
7
+ * Improvement: Switch to mimemagic gem for content-type detection
8
+ * Improvement: Allows multiple content types for spoof detector
9
+ * Bug Fix: Don't assume we have Rails.env if we have Rails
10
+ * Performance: Decrease Memory footprint
11
+ * Ruby Versioning: Drop support for 1.9.3 (EOL'ed)
12
+ * Rails Versioning: Drop support for 4.0.0 (EOL'ed)
13
+
1
14
  4.2.4:
2
15
 
3
16
  * Rollback backwards incompatible change, allowing paperclip to run on
@@ -22,7 +35,7 @@
22
35
  * Improvement: Better escaping for characters in URLs
23
36
  * Improvement: Honor `fog_credentials[:scheme]`
24
37
  * Improvement: Also look for custom processors in lib/paperclip
25
- * Improvement: id partitioning for string IDs works liks integer id
38
+ * Improvement: id partitioning for string IDs works like integer id
26
39
  * Improvement: Can pass options to DB adapters in migrations
27
40
  * Improvement: Update expiring_url creation for later versions of fog
28
41
  * Improvement: `path` can be a Proc in S3 attachments
data/README.md CHANGED
@@ -1,7 +1,46 @@
1
1
  Paperclip
2
2
  =========
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.png?branch=master)](http://travis-ci.org/thoughtbot/paperclip) [![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.png?travis)](https://gemnasium.com/thoughtbot/paperclip) [![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.png)](https://codeclimate.com/github/thoughtbot/paperclip) [![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.png)](http://inch-ci.org/github/thoughtbot/paperclip) [![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
4
+ [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.svg?branch=master)](http://travis-ci.org/thoughtbot/paperclip) [![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.svg?travis)](https://gemnasium.com/thoughtbot/paperclip) [![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.svg)](https://codeclimate.com/github/thoughtbot/paperclip) [![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.svg)](http://inch-ci.org/github/thoughtbot/paperclip) [![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
5
+
6
+ - [Requirements](#requirements)
7
+ - [Ruby on Rails](#ruby-and-rails)
8
+ - [Image Processor](#image-processor)
9
+ - [file](#file)
10
+ - [Installation](#installation)
11
+ - [Quick Start](#quick-start)
12
+ - [Models](#models)
13
+ - [Migrations](#migrations)
14
+ - [Edit and New Views](#edit-and-new-views)
15
+ - [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
16
+ - [Controller](#controller)
17
+ - [Show View](#show-view)
18
+ - [Deleting an Attachment](#deleting-an-attachment)
19
+ - [Usage](#usage)
20
+ - [Validations](#validations)
21
+ - [Security Validations](#security-validations)
22
+ - [Defaults](#defaults)
23
+ - [Migrations](#migrations-1)
24
+ - [Table Definition](#table-definition)
25
+ - [Schema Definition](#schema-definition)
26
+ - [Vintage Syntax](#vintage-syntax)
27
+ - [Storage](#storage)
28
+ - [Understanding Storage](#understanding-storage)
29
+ - [Post Processing](#post-processing)
30
+ - [Events](#events)
31
+ - [URI Obfuscation](#uri-obfuscation)
32
+ - [MD5 Checksum / Fingerprint](#md5-checksum--fingerprint)
33
+ - [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
34
+ - [Custom Attachment Processors](#custom-attachment-processors)
35
+ - [Dynamic Configuration](#dynamic-configuration)
36
+ - [Dynamic Styles](#dynamic-styles)
37
+ - [Dynamic Processors](#dynamic-processors)
38
+ - [Logging](#logging)
39
+ - [Deployment](#deployment)
40
+ - [Testing](#testing)
41
+ - [Contributing](#contributing)
42
+ - [License](#license)
43
+ - [About thoughtbot](#about-thoughtbot)
5
44
 
6
45
  Paperclip is intended as an easy file attachment library for Active Record. The
7
46
  intent behind it was to keep setup as easy as possible and to treat files as
@@ -27,7 +66,7 @@ Requirements
27
66
 
28
67
  ### Ruby and Rails
29
68
 
30
- Paperclip now requires Ruby version **>= 1.9.2** and Rails version **>= 3.0** (Only if you're going to use Paperclip with Ruby on Rails.)
69
+ Paperclip now requires Ruby version **>= 2.0.0** and Rails version **3.2, >= 4.1** (Only if you're going to use Paperclip with Ruby on Rails.)
31
70
 
32
71
  If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still use Paperclip 2.7.x with your project. Also, everything in this README might not apply to your version of Paperclip, and you should read [the README for version 2.7](http://rubydoc.info/gems/paperclip/2.7.0) instead.
33
72
 
@@ -52,15 +91,15 @@ If you're on Mac OS X, you'll want to run the following with Homebrew:
52
91
  brew install imagemagick
53
92
 
54
93
  If you are dealing with pdf uploads or running the test suite, you'll also need
55
- GhostScript to be installed. On Mac OS X, you can also install that using Homebrew:
94
+ to install GhostScript. On Mac OS X, you can also install that using Homebrew:
56
95
 
57
96
  brew install gs
58
97
 
59
98
  ### `file`
60
99
 
61
- The Unix [`file` command](http://en.wikipedia.org/wiki/File_(command)) is required for content type checking.
62
- This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
63
- so Windows users must make sure that the devkit is installed and added to system `PATH`.
100
+ The Unix [`file` command](http://en.wikipedia.org/wiki/File_(command)) is required for content-type checking.
101
+ This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
102
+ so Windows users must make sure that the devkit is installed and added to the system `PATH`.
64
103
 
65
104
  **Manual Installation**
66
105
 
@@ -70,21 +109,21 @@ To manually install, you should perform the following:
70
109
 
71
110
  > **Download & install `file` from [this URL](http://gnuwin32.sourceforge.net/packages/file.htm)**
72
111
 
73
- To test, you can use the following:
112
+ To test, you can use the image below:
74
113
  ![untitled](https://cloud.githubusercontent.com/assets/1104431/4524452/a1f8cce4-4d44-11e4-872e-17adb96f79c9.png)
75
114
 
76
- Next, you need to integrate with your environment - preferrably through the `PATH` variable, or by changing your `config/environments/development.rb` file
115
+ Next, you need to integrate with your environment - preferably through the `PATH` variable, or by changing your `config/environments/development.rb` file
77
116
 
78
117
  **PATH**
79
118
 
80
119
  1. Click "Start"
81
120
  2. On "Computer", right-click and select "Properties"
82
- 3. In properties, select "Advanced System Settings"
121
+ 3. In Properties, select "Advanced System Settings"
83
122
  4. Click the "Environment Variables" button
84
123
  5. Locate the "PATH" var - at the end, add the path to your newly installed `file.exe` (typically `C:\Program Files (x86)\GnuWin32\bin`)
85
124
  6. Restart any CMD shells you have open & see if it works
86
125
 
87
- OR
126
+ OR
88
127
 
89
128
  **Environment**
90
129
 
@@ -92,7 +131,7 @@ OR
92
131
  2. Add the following line: `Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'`
93
132
  3. Restart your Rails server
94
133
 
95
- Either of these methods will give your Rails setup access to the `file.exe` functionality, this providing the ability to check the contents of a file (fixing the spoofing problem)
134
+ Either of these methods will give your Rails setup access to the `file.exe` functionality, thus providing the ability to check the contents of a file (fixing the spoofing problem)
96
135
 
97
136
  ---
98
137
 
@@ -163,17 +202,17 @@ end
163
202
 
164
203
  ```ruby
165
204
  class AddAvatarColumnsToUsers < ActiveRecord::Migration
166
- def self.up
205
+ def up
167
206
  add_attachment :users, :avatar
168
207
  end
169
208
 
170
- def self.down
209
+ def down
171
210
  remove_attachment :users, :avatar
172
211
  end
173
212
  end
174
213
  ```
175
214
 
176
- (Or you can use migration generator: `rails generate paperclip user avatar`)
215
+ (Or you can use the Rails migration generator: `rails generate paperclip user avatar`)
177
216
 
178
217
  ### Edit and New Views
179
218
 
@@ -183,6 +222,13 @@ end
183
222
  <% end %>
184
223
  ```
185
224
 
225
+ ### Edit and New Views with Simple Form
226
+ ```erb
227
+ <%= simple_form_for @user, url: users_path do |form| %>
228
+ <%= form.input :avatar, as: :file %>
229
+ <% end %>
230
+ ```
231
+
186
232
  ### Controller
187
233
 
188
234
  **Rails 3**
@@ -231,7 +277,7 @@ Set the attribute to `nil` and save.
231
277
  Usage
232
278
  -----
233
279
 
234
- The basics of paperclip are quite simple: Declare that your model has an
280
+ The basics of Paperclip are quite simple: Declare that your model has an
235
281
  attachment with the `has_attached_file` method, and give it a name.
236
282
 
237
283
  Paperclip will wrap up to four attributes (all prefixed with that attachment's name,
@@ -243,11 +289,11 @@ friendly front end. These attributes are:
243
289
  * `<attachment>_content_type`
244
290
  * `<attachment>_updated_at`
245
291
 
246
- By default, only `<attachment>_file_name` is required for paperclip to operate.
292
+ By default, only `<attachment>_file_name` is required for Paperclip to operate.
247
293
  You'll need to add `<attachment>_content_type` in case you want to use content type
248
294
  validation.
249
295
 
250
- More information about the options to `has_attached_file` is available in the
296
+ More information about the options passed to `has_attached_file` is available in the
251
297
  documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
252
298
 
253
299
  Validations
@@ -288,8 +334,8 @@ validates_attachment :avatar, :presence => true,
288
334
  :size => { :in => 0..10.kilobytes }
289
335
  ```
290
336
 
291
- _NOTE: Post processing will not even *start* if the attachment is not valid
292
- according to the validations. Your callbacks and processors will *only* be
337
+ _NOTE: Post-processing will not even **start** if the attachment is not valid
338
+ according to the validations. Your callbacks and processors will **only** be
293
339
  called with valid attachments._
294
340
 
295
341
  ```ruby
@@ -382,18 +428,18 @@ NOTE: Also starting at version 4.0.0, Paperclip has another validation that
382
428
  cannot be turned off. This validation will prevent content type spoofing. That
383
429
  is, uploading a PHP document (for example) as part of the EXIF tags of a
384
430
  well-formed JPEG. This check is limited to the media type (the first part of the
385
- MIME type, so, 'text' in 'text/plain'). This will prevent HTML documents from
431
+ MIME type, so, 'text' in `text/plain`). This will prevent HTML documents from
386
432
  being uploaded as JPEGs, but will not prevent GIFs from being uploaded with a
387
- .jpg extension. This validation will only add validation errors to the form. It
388
- will not cause Errors to be raised.
433
+ `.jpg` extension. This validation will only add validation errors to the form. It
434
+ will not cause errors to be raised.
389
435
 
390
- This can sometimes cause false validation errors in applications that use custom
436
+ This can sometimes cause false validation errors in applications that use custom
391
437
  file extensions. In these cases you may wish to add your custom extension to the
392
- list of file extensions allowed for your mime type configured by the mime-types
438
+ list of file extensions allowed for your MIME type configured by the `mime-types`
393
439
  gem:
394
440
 
395
441
  ```ruby
396
- # Allow ".foo" as an extension for files with the mime type "text/plain".
442
+ # Allow ".foo" as an extension for files with the MIME type "text/plain".
397
443
  text_plain = MIME::Types["text/plain"].first
398
444
  text_plain.extensions << "foo"
399
445
  MIME::Types.index_extensions text_plain
@@ -403,9 +449,9 @@ MIME::Types.index_extensions text_plain
403
449
 
404
450
  Defaults
405
451
  --------
406
- Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.
452
+ Global defaults for all your Paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash. This can be useful for setting your default storage settings per example so you won't have to define them in every `has_attached_file` definition.
407
453
 
408
- If you're using Rails you can define a Hash with default options in config/application.rb or in any of the config/environments/*.rb files on config.paperclip_defaults, these will get merged into Paperclip::Attachment.default_options as your Rails app boots. An example:
454
+ If you're using Rails, you can define a Hash with default options in `config/application.rb` or in any of the `config/environments/*.rb` files on config.paperclip_defaults. These will get merged into `Paperclip::Attachment.default_options` as your Rails app boots. An example:
409
455
 
410
456
  ```ruby
411
457
  module YourApp
@@ -417,7 +463,7 @@ module YourApp
417
463
  end
418
464
  ```
419
465
 
420
- Another option is to directly modify the Paperclip::Attachment.default_options Hash, this method works for non-Rails applications or is an option if you prefer to place the Paperclip default settings in an initializer.
466
+ Another option is to directly modify the `Paperclip::Attachment.default_options` Hash - this method works for non-Rails applications or is an option if you prefer to place the Paperclip default settings in an initializer.
421
467
 
422
468
  An example Rails initializer would look something like this:
423
469
 
@@ -432,25 +478,31 @@ Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
432
478
  Migrations
433
479
  ----------
434
480
 
435
- Paperclip defines several migration methods which can be used to create necessary columns in your
436
- model. There are two types of method:
481
+ Paperclip defines several migration methods which can be used to create the necessary columns in your
482
+ model. There are two types of helper methods to aid in this, as follows:
483
+
484
+ ### Add Attachment Column To A Table
437
485
 
438
- ### Table Definition
486
+ The `attachment` helper can be used when creating a table:
439
487
 
440
488
  ```ruby
441
- class AddAttachmentToUsers < ActiveRecord::Migration
442
- def self.up
489
+ class CreateUsersWithAttachments < ActiveRecord::Migration
490
+ def up
443
491
  create_table :users do |t|
444
492
  t.attachment :avatar
445
493
  end
494
+
495
+ # This is assuming you are only using the users table for Paperclip attachment. Drop with care!
496
+ def down
497
+ drop_table :users
446
498
  end
447
499
  end
448
500
  ```
449
501
 
450
- If you're using Rails 3.2 or newer, this method works in `change` method as well:
502
+ You can also use the `change` method, instead of the `up`/`down` combination above, as shown below:
451
503
 
452
504
  ```ruby
453
- class AddAttachmentToUsers < ActiveRecord::Migration
505
+ class CreateUsersWithAttachments < ActiveRecord::Migration
454
506
  def change
455
507
  create_table :users do |t|
456
508
  t.attachment :avatar
@@ -461,22 +513,24 @@ end
461
513
 
462
514
  ### Schema Definition
463
515
 
516
+ Alternatively, the `add_attachment` and `remove_attachment` methods can be used to add new Paperclip columns to an existing table:
517
+
464
518
  ```ruby
465
- class AddAttachmentToUsers < ActiveRecord::Migration
466
- def self.up
519
+ class AddAttachmentColumnsToUsers < ActiveRecord::Migration
520
+ def up
467
521
  add_attachment :users, :avatar
468
522
  end
469
523
 
470
- def self.down
524
+ def down
471
525
  remove_attachment :users, :avatar
472
526
  end
473
527
  end
474
528
  ```
475
529
 
476
- If you're using Rails 3.2 or newer, you only need `add_attachment` in your `change` method:
530
+ Or you can do this with the `change` method:
477
531
 
478
532
  ```ruby
479
- class AddAttachmentToUsers < ActiveRecord::Migration
533
+ class AddAttachmentColumnsToUsers < ActiveRecord::Migration
480
534
  def change
481
535
  add_attachment :users, :avatar
482
536
  end
@@ -485,7 +539,7 @@ end
485
539
 
486
540
  ### Vintage syntax
487
541
 
488
- Vintage syntax (such as `t.has_attached_file` and `drop_attached_file`) are still supported in
542
+ Vintage syntax (such as `t.has_attached_file` and `drop_attached_file`) is still supported in
489
543
  Paperclip 3.x, but you're advised to update those migration files to use this new syntax.
490
544
 
491
545
  ---
@@ -524,7 +578,7 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
524
578
  the `aws-sdk` gem in your Gemfile:
525
579
 
526
580
  ```ruby
527
- gem 'aws-sdk', '~> 1.5.7'
581
+ gem 'aws-sdk', '~> 1.6'
528
582
  ```
529
583
 
530
584
  And then you can specify using S3 from `has_attached_file`.
@@ -545,12 +599,12 @@ Post Processing
545
599
 
546
600
  Paperclip supports an extensible selection of post-processors. When you define
547
601
  a set of styles for an attachment, by default it is expected that those
548
- "styles" are actually "thumbnails". However, you can do much more than just
602
+ "styles" are actually "thumbnails." However, you can do much more than just
549
603
  thumbnail images. By defining a subclass of Paperclip::Processor, you can
550
604
  perform any processing you want on the files that are attached. Any file in
551
605
  your Rails app's `lib/paperclip` and `lib/paperclip_processors` directories is
552
- automatically loaded by paperclip, allowing you to easily define custom
553
- processors. You can specify a processor with the :processors option to
606
+ automatically loaded by Paperclip, allowing you to easily define custom
607
+ processors. You can specify a processor with the `:processors` option to
554
608
  `has_attached_file`:
555
609
 
556
610
  ```ruby
@@ -564,21 +618,21 @@ more information about defining processors, see Paperclip::Processor.
564
618
 
565
619
  The default processor is Paperclip::Thumbnail. For backwards compatibility
566
620
  reasons, you can pass a single geometry string or an array containing a
567
- geometry and a format, which the file will be converted to, like so:
621
+ geometry and a format that the file will be converted to, like so:
568
622
 
569
623
  ```ruby
570
624
  has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }
571
625
  ```
572
626
 
573
- This will convert the "thumb" style to a 32x32 square in png format, regardless
627
+ This will convert the "thumb" style to a 32x32 square in PNG format, regardless
574
628
  of what was uploaded. If the format is not specified, it is kept the same (i.e.
575
- jpgs will remain jpgs). For more information on the accepted style formats, see
629
+ JPGs will remain JPGs). For more information on the accepted style formats, see
576
630
  [here](http://www.imagemagick.org/script/command-line-processing.php#geometry).
577
631
 
578
632
  Multiple processors can be specified, and they will be invoked in the order
579
- they are defined in the :processors array. Each successive processor will
633
+ they are defined in the `:processors` array. Each successive processor will
580
634
  be given the result of the previous processor's execution. All processors will
581
- receive the same parameters, which are what you define in the :styles hash.
635
+ receive the same parameters, which are defined in the `:styles` hash.
582
636
  For example, assuming we had this definition:
583
637
 
584
638
  ```ruby
@@ -587,7 +641,7 @@ has_attached_file :scan, :styles => { :text => { :quality => :better } },
587
641
  ```
588
642
 
589
643
  then both the :rotator processor and the :ocr processor would receive the
590
- options "{ :quality => :better }". This parameter may not mean anything to one
644
+ options `{ :quality => :better }`. This parameter may not mean anything to one
591
645
  or more or the processors, and they are expected to ignore it.
592
646
 
593
647
  _NOTE: Because processors operate by turning the original attachment into the
@@ -615,8 +669,8 @@ normal ActiveRecord callbacks as possible, so if you return false (specifically
615
669
  will halt. Returning false in an `after_filter` will not halt anything, but you
616
670
  can access the model and the attachment if necessary.
617
671
 
618
- _NOTE: Post processing will not even *start* if the attachment is not valid
619
- according to the validations. Your callbacks and processors will *only* be
672
+ _NOTE: Post processing will not even **start** if the attachment is not valid
673
+ according to the validations. Your callbacks and processors will **only** be
620
674
  called with valid attachments._
621
675
 
622
676
  ```ruby
@@ -652,24 +706,24 @@ has_attached_file :avatar, {
652
706
  The `:hash` interpolation will be replaced with a unique hash made up of whatever
653
707
  is specified in `:hash_data`. The default value for `:hash_data` is `":class/:attachment/:id/:style/:updated_at"`.
654
708
 
655
- `:hash_secret` is required, an exception will be raised if `:hash` is used without `:hash_secret` present.
709
+ `:hash_secret` is required - an exception will be raised if `:hash` is used without `:hash_secret` present.
656
710
 
657
- For more on this feature read the author's own explanation. [https://github.com/thoughtbot/paperclip/pull/416](https://github.com/thoughtbot/paperclip/pull/416)
711
+ For more on this feature, read [the author's own explanation](https://github.com/thoughtbot/paperclip/pull/416)
658
712
 
659
713
  MD5 Checksum / Fingerprint
660
714
  -------
661
715
 
662
- A MD5 checksum of the original file assigned will be placed in the model if it
716
+ An MD5 checksum of the original file assigned will be placed in the model if it
663
717
  has an attribute named fingerprint. Following the user model migration example
664
- above, the migration would look like the following.
718
+ above, the migration would look like the following:
665
719
 
666
720
  ```ruby
667
721
  class AddAvatarFingerprintColumnToUser < ActiveRecord::Migration
668
- def self.up
722
+ def up
669
723
  add_column :users, :avatar_fingerprint, :string
670
724
  end
671
725
 
672
- def self.down
726
+ def down
673
727
  remove_column :users, :avatar_fingerprint
674
728
  end
675
729
  end
@@ -698,11 +752,11 @@ to inherit from `Paperclip::Processor` (see `lib/paperclip/processor.rb`).
698
752
  For example, when `:styles` are specified for an image attachment, the
699
753
  thumbnail processor (see `lib/paperclip/thumbnail.rb`) is loaded without having
700
754
  to specify it as a `:processor` parameter to `has_attached_file`. When any
701
- other processor is defined it must be called out in the `:processors`
755
+ other processor is defined, it must be called out in the `:processors`
702
756
  parameter if it is to be applied to the attachment. The thumbnail processor
703
- uses the imagemagick `convert` command to do the work of resizing image
757
+ uses the ImageMagick `convert` command to do the work of resizing image
704
758
  thumbnails. It would be easy to create a custom processor that watermarks
705
- an image using imagemagick's `composite` command. Following the
759
+ an image using ImageMagick's `composite` command. Following the
706
760
  implementation pattern of the thumbnail processor would be a way to implement a
707
761
  watermark processor. All kinds of attachment processors can be created;
708
762
  a few utility examples would be compression and encryption processors.
@@ -722,7 +776,7 @@ instances.
722
776
  ### Dynamic Styles:
723
777
 
724
778
  Imagine a user model that had different styles based on the role of the user.
725
- Perhaps some users are bosses (e.g. a User model instance responds to #boss?)
779
+ Perhaps some users are bosses (e.g. a User model instance responds to `#boss?`)
726
780
  and merit a bigger avatar thumbnail than regular users. The configuration to
727
781
  determine what style parameters are to be used based on the user role might
728
782
  look as follows where a boss will receive a `300x300` thumbnail otherwise a
@@ -788,7 +842,11 @@ namespace :deploy do
788
842
  desc "build missing paperclip styles"
789
843
  task :build_missing_paperclip_styles do
790
844
  on roles(:app) do
791
- execute "cd #{current_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
845
+ within release_path do
846
+ with rails_env: fetch(:rails_env) do
847
+ execute :rake, "paperclip:refresh:missing_styles"
848
+ end
849
+ end
792
850
  end
793
851
  end
794
852
  end
@@ -797,7 +855,7 @@ after("deploy:compile_assets", "deploy:build_missing_paperclip_styles")
797
855
  ```
798
856
 
799
857
  Now you don't have to remember to refresh thumbnails in production every time you add a new style.
800
- Unfortunately it does not work with dynamic styles - it just ignores them.
858
+ Unfortunately, it does not work with dynamic styles - it just ignores them.
801
859
 
802
860
  If you already have a working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
803
861
  Paperclip about existing styles. Simply create a `paperclip_attachments.yml` file by hand. For example:
@@ -855,7 +913,7 @@ else
855
913
  end
856
914
  ```
857
915
 
858
- The important part here being the inclusion of `ENV['TEST_ENV_NUMBER']`, or the
916
+ The important part here being the inclusion of `ENV['TEST_ENV_NUMBER']`, or a
859
917
  similar mechanism for whichever parallel testing library you use.
860
918
 
861
919
  **Integration Tests**
@@ -893,23 +951,25 @@ guidelines:
893
951
 
894
952
  Please see `CONTRIBUTING.md` for more details on contributing and running test.
895
953
 
896
- ---
954
+ Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
897
955
 
898
- Credits
956
+ License
899
957
  -------
900
958
 
901
- ![thoughtbot](http://thoughtbot.com/logo.png)
959
+ Paperclip is Copyright © 2008-2015 thoughtbot, inc. It is free software, and may be
960
+ redistributed under the terms specified in the MIT-LICENSE file.
902
961
 
903
- Paperclip is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
962
+ About thoughtbot
963
+ ----------------
904
964
 
905
- Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
965
+ ![thoughtbot](https://thoughtbot.com/logo.png)
906
966
 
967
+ Paperclip is maintained and funded by thoughtbot.
907
968
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
908
969
 
909
- ---
910
-
911
- License
912
- -------
970
+ We love open source software!
971
+ See [our other projects][community] or
972
+ [hire us][hire] to design, develop, and grow your product.
913
973
 
914
- Paperclip is Copyright © 2008-2014 thoughtbot, inc. It is free software, and may be
915
- redistributed under the terms specified in the MIT-LICENSE file.
974
+ [community]: https://thoughtbot.com/community?utm_source=github
975
+ [hire]: https://thoughtbot.com?utm_source=github