kt-paperclip 6.2.1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/custom.md +10 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.hound.yml +364 -357
- data/.rubocop.yml +2 -0
- data/.travis.yml +12 -14
- data/Appraisals +6 -0
- data/Gemfile +3 -3
- data/NEWS +28 -0
- data/README.md +41 -19
- data/features/step_definitions/attachment_steps.rb +11 -1
- data/gemfiles/4.2.gemfile +1 -1
- data/gemfiles/5.0.gemfile +1 -1
- data/gemfiles/5.1.gemfile +1 -1
- data/gemfiles/5.2.gemfile +1 -1
- data/gemfiles/6.0.gemfile +1 -1
- data/gemfiles/6.1.gemfile +21 -0
- data/lib/paperclip.rb +3 -3
- data/lib/paperclip/content_type_detector.rb +4 -4
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
- data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
- data/lib/paperclip/schema.rb +2 -2
- data/lib/paperclip/storage/s3.rb +2 -2
- data/lib/paperclip/url_generator.rb +8 -1
- data/lib/paperclip/validators.rb +4 -4
- data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
- data/lib/paperclip/validators/attachment_file_name_validator.rb +9 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +18 -2
- data/lib/paperclip/version.rb +1 -1
- data/paperclip.gemspec +4 -4
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
- data/spec/paperclip/storage/s3_spec.rb +54 -3
- data/spec/paperclip/url_generator_spec.rb +10 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
- data/spec/support/fixtures/aws_s3.yml +13 -0
- data/spec/support/model_reconstruction.rb +1 -1
- metadata +17 -12
- data/.github/issue_template.md +0 -3
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.1
|
5
|
-
- 2.2
|
6
4
|
- 2.3
|
7
5
|
- 2.4
|
8
6
|
- 2.5
|
9
7
|
- 2.6
|
8
|
+
- 2.7
|
10
9
|
|
11
10
|
script: "bundle exec rake clean spec cucumber"
|
12
11
|
|
@@ -25,23 +24,22 @@ gemfile:
|
|
25
24
|
- gemfiles/5.1.gemfile
|
26
25
|
- gemfiles/5.2.gemfile
|
27
26
|
- gemfiles/6.0.gemfile
|
27
|
+
- gemfiles/6.1.gemfile
|
28
28
|
|
29
29
|
matrix:
|
30
30
|
fast_finish: true
|
31
31
|
exclude:
|
32
|
-
- gemfile: gemfiles/5.0.gemfile
|
33
|
-
rvm: 2.1
|
34
|
-
- gemfile: gemfiles/5.1.gemfile
|
35
|
-
rvm: 2.1
|
36
|
-
- gemfile: gemfiles/5.2.gemfile
|
37
|
-
rvm: 2.1
|
38
|
-
- gemfile: gemfiles/5.2.gemfile
|
39
|
-
rvm: 2.2
|
40
|
-
- gemfile: gemfiles/6.0.gemfile
|
41
|
-
rvm: 2.1
|
42
|
-
- gemfile: gemfiles/6.0.gemfile
|
43
|
-
rvm: 2.2
|
44
32
|
- gemfile: gemfiles/6.0.gemfile
|
45
33
|
rvm: 2.3
|
46
34
|
- gemfile: gemfiles/6.0.gemfile
|
47
35
|
rvm: 2.4
|
36
|
+
- gemfile: gemfiles/6.1.gemfile
|
37
|
+
rvm: 2.3
|
38
|
+
- gemfile: gemfiles/6.1.gemfile
|
39
|
+
rvm: 2.4
|
40
|
+
- gemfile: gemfiles/4.2.gemfile
|
41
|
+
rvm: 2.7
|
42
|
+
- gemfile: gemfiles/5.0.gemfile
|
43
|
+
rvm: 2.7
|
44
|
+
- gemfile: gemfiles/5.1.gemfile
|
45
|
+
rvm: 2.7
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
@@ -8,11 +8,11 @@ gem "pry"
|
|
8
8
|
# Prevents bundler from taking a long-time to resolve
|
9
9
|
group :development, :test do
|
10
10
|
gem "activerecord-import"
|
11
|
-
gem
|
11
|
+
gem "bootsnap", require: false
|
12
12
|
gem "builder"
|
13
|
-
gem
|
14
|
-
gem "mime-types"
|
13
|
+
gem "listen", "~> 3.0.8"
|
15
14
|
gem "rspec"
|
16
15
|
gem "rubocop", require: false
|
16
|
+
gem "rubocop-rails"
|
17
17
|
gem "sprockets", "3.7.2"
|
18
18
|
end
|
data/NEWS
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
7.0.0 (2021-05-28)
|
2
|
+
* Replace `mimemagic` gem with `marcel` due to licensing issues. See https://github.com/kreeti/kt-paperclip/pull/54 for details and limitations
|
3
|
+
|
4
|
+
6.4.1 (2021-01-30)
|
5
|
+
* Improvement: Use URI.open in ruby > 2.5 (PR #45)
|
6
|
+
|
7
|
+
6.4.0 (2020-12-14)
|
8
|
+
* Improvement: Fix Ruby 2.7 method & syntax deprecation warnings (#38)
|
9
|
+
|
10
|
+
6.3.0 (2020-08-10)
|
11
|
+
* Feature: Add validation_errors_to option - customize copying of errors (#26)
|
12
|
+
* Stability: Dropped support for ruby 2.1
|
13
|
+
|
14
|
+
6.2.2 (2020-02-18)
|
15
|
+
* Bugfix: Add support for Aliases in S3 credentials YAML (accidentally removed during 6.2.0 upgrade).
|
16
|
+
|
17
|
+
6.2.1 (2020-01-30)
|
18
|
+
|
19
|
+
* Bugfix: Auto-loading of the gem code (necessitated due to change in gem name).
|
20
|
+
|
21
|
+
6.2.0 (2020-01-23):
|
22
|
+
|
23
|
+
* Bugfix: Don't do post-processing on invalid attachments (#16).
|
24
|
+
* Improvement: Use AWS::S3 built in download_file method (#9).
|
25
|
+
* Stability: Rubocop recommended syntax updates (#10, #11, #13, #14).
|
26
|
+
* Stability: Testing - replace mocha and bourne with rspec mocks (#6).
|
27
|
+
* Stability: Fix test suite to run with Rails 5 and Rails 6 (#19, #20, #7).
|
28
|
+
|
1
29
|
6.1.0 (2018-07-27):
|
2
30
|
|
3
31
|
* BUGFIX: Don't double-encode URLs (Roderick Monje).
|
data/README.md
CHANGED
@@ -10,12 +10,11 @@ Please feel free to contribute Issues and pull requests.
|
|
10
10
|
## Documentation valid for `master` branch
|
11
11
|
|
12
12
|
Please check the documentation for the paperclip version you are using:
|
13
|
-
https://github.com/kreeti/paperclip/releases
|
13
|
+
https://github.com/kreeti/kt-paperclip/releases
|
14
14
|
|
15
15
|
---
|
16
16
|
|
17
|
-
[![Build Status](https://
|
18
|
-
[![Dependency Status](https://gemnasium.com/kreeti/paperclip.svg?travis)](https://gemnasium.com/kreeti/paperclip)
|
17
|
+
[![Build Status](https://travis-ci.com/kreeti/kt-paperclip.svg?branch=master)](https://travis-ci.com/kreeti/kt-paperclip)
|
19
18
|
[![Code Climate](https://codeclimate.com/github/kreeti/paperclip.svg)](https://codeclimate.com/github/kreeti/paperclip)
|
20
19
|
[![Inline docs](http://inch-ci.org/github/kreeti/paperclip.svg)](http://inch-ci.org/github/kreeti/paperclip)
|
21
20
|
[![Security](https://hakiri.io/github/kreeti/paperclip/master.svg)](https://hakiri.io/github/kreeti/paperclip/master)
|
@@ -79,10 +78,10 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
79
78
|
browser by an easily understandable specification, which has sensible and
|
80
79
|
useful defaults.
|
81
80
|
|
82
|
-
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
81
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/ClassMethods) for
|
83
82
|
more detailed options.
|
84
83
|
|
85
|
-
The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
|
84
|
+
The complete [RDoc](http://www.rubydoc.info/gems/kt-paperclip) is online.
|
86
85
|
|
87
86
|
---
|
88
87
|
|
@@ -91,7 +90,7 @@ Requirements
|
|
91
90
|
|
92
91
|
### Ruby and Rails
|
93
92
|
|
94
|
-
Paperclip now requires Ruby version **>= 2.
|
93
|
+
Paperclip now requires Ruby version **>= 2.3** and Rails version **>= 4.2**
|
95
94
|
(only if you're going to use Paperclip with Ruby on Rails).
|
96
95
|
|
97
96
|
### Image Processor
|
@@ -172,13 +171,13 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
172
171
|
Include the gem in your Gemfile:
|
173
172
|
|
174
173
|
```ruby
|
175
|
-
gem "kt-paperclip", "~> 6.
|
174
|
+
gem "kt-paperclip", "~> 6.4", ">= 6.4.1"
|
176
175
|
```
|
177
176
|
|
178
177
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
179
178
|
|
180
179
|
```ruby
|
181
|
-
gem "kt-paperclip", git: "git://github.com/kreeti/paperclip.git"
|
180
|
+
gem "kt-paperclip", git: "git://github.com/kreeti/kt-paperclip.git"
|
182
181
|
```
|
183
182
|
|
184
183
|
If you're trying to use features that don't seem to be in the latest released gem, but are
|
@@ -310,7 +309,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
|
|
310
309
|
validation.
|
311
310
|
|
312
311
|
More information about the options passed to `has_attached_file` is available in the
|
313
|
-
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
312
|
+
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/ClassMethods).
|
314
313
|
|
315
314
|
Validations
|
316
315
|
-----------
|
@@ -342,7 +341,7 @@ Example Usage:
|
|
342
341
|
validates_attachment_presence :avatar
|
343
342
|
```
|
344
343
|
|
345
|
-
|
344
|
+
You can also define multiple validations on a single attachment using `validates_attachment`:
|
346
345
|
|
347
346
|
```ruby
|
348
347
|
validates_attachment :avatar, presence: true,
|
@@ -411,6 +410,28 @@ validates_attachment :avatar,
|
|
411
410
|
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
|
412
411
|
inferred content_type, regardless of the actual contents of the file.
|
413
412
|
|
413
|
+
### Duplicate error messages
|
414
|
+
|
415
|
+
By default Paperclip will copy validation errors from the attribute to the base
|
416
|
+
of your model. Depending on how you display your validation errors, this can lead
|
417
|
+
to confusing duplicate errors (one on the attribute and another referring to the
|
418
|
+
base model).
|
419
|
+
|
420
|
+
You can override this behaviour with the `add_validation_errors_to` option. By
|
421
|
+
default this is set to `:both` but can be set to either `:attribute` or `:base`.
|
422
|
+
|
423
|
+
* `:both` creates errors on both the attribute and base model.
|
424
|
+
* `:attribute` only creates an error on the attribute of the model.
|
425
|
+
* `:base` only creates an error on the base model.
|
426
|
+
|
427
|
+
You can set this option globally:
|
428
|
+
|
429
|
+
`Paperclip.options[:add_validation_errors_to] = :attribute`
|
430
|
+
|
431
|
+
or pass it in to an individual validation declaration:
|
432
|
+
|
433
|
+
`validates_attachment :document, content_type: { content_type: "application/pdf" }, add_validation_errors_to: :attribute`
|
434
|
+
|
414
435
|
---
|
415
436
|
|
416
437
|
Internationalization (I18n)
|
@@ -606,7 +627,7 @@ gem 'aws-sdk-s3'
|
|
606
627
|
|
607
628
|
And then you can specify using S3 from `has_attached_file`.
|
608
629
|
You can find more information about configuring and using S3 storage in
|
609
|
-
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
630
|
+
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/Storage/S3).
|
610
631
|
|
611
632
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
612
633
|
available to the internet at large. If you require access control, it's
|
@@ -689,7 +710,7 @@ Custom Attachment Processors
|
|
689
710
|
You can write your own custom attachment processors to carry out tasks like
|
690
711
|
adding watermarks, compressing images, or encrypting files. Custom processors
|
691
712
|
must be defined within the `Paperclip` module, inherit from
|
692
|
-
`Paperclip::Processor` (see [`lib/paperclip/processor.rb`](https://github.com/kreeti/paperclip/blob/master/lib/paperclip/processor.rb)),
|
713
|
+
`Paperclip::Processor` (see [`lib/paperclip/processor.rb`](https://github.com/kreeti/kt-paperclip/blob/master/lib/paperclip/processor.rb)),
|
693
714
|
and implement a `make` method that returns a `File`. All files in your Rails
|
694
715
|
app's `lib/paperclip` and `lib/paperclip_processors` directories will be
|
695
716
|
automatically loaded by Paperclip. Processors are specified using the
|
@@ -892,7 +913,7 @@ Your::Application.configure do
|
|
892
913
|
end
|
893
914
|
```
|
894
915
|
|
895
|
-
More information in the [rdocs](
|
916
|
+
More information in the [rdocs](https://www.rubydoc.info/gems/kt-paperclip/Paperclip.options)
|
896
917
|
|
897
918
|
---
|
898
919
|
|
@@ -976,7 +997,7 @@ Testing
|
|
976
997
|
-------
|
977
998
|
|
978
999
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
979
|
-
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
1000
|
+
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/Shoulda/Matchers)
|
980
1001
|
for more information.
|
981
1002
|
|
982
1003
|
**Parallel Tests**
|
@@ -1036,18 +1057,19 @@ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
|
|
1036
1057
|
fix/feature has a high chance of being included, please read the following
|
1037
1058
|
guidelines:
|
1038
1059
|
|
1039
|
-
1. Post a [pull request](https://github.com/kreeti/paperclip/compare/).
|
1060
|
+
1. Post a [pull request](https://github.com/kreeti/kt-paperclip/compare/).
|
1040
1061
|
2. Make sure there are tests! We will not accept any patch that is not tested.
|
1041
1062
|
It's a rare time when explicit tests aren't needed. If you have questions
|
1042
1063
|
about writing tests for paperclip, please open a
|
1043
|
-
[GitHub issue](https://github.com/kreeti/paperclip/issues/new).
|
1064
|
+
[GitHub issue](https://github.com/kreeti/kt-paperclip/issues/new).
|
1044
1065
|
|
1045
1066
|
Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
|
1046
1067
|
|
1047
|
-
Thank you to all [the contributors](https://github.com/kreeti/paperclip/graphs/contributors)!
|
1068
|
+
Thank you to all [the contributors](https://github.com/kreeti/kt-paperclip/graphs/contributors)!
|
1048
1069
|
|
1049
1070
|
License
|
1050
1071
|
-------
|
1051
1072
|
|
1052
|
-
|
1053
|
-
|
1073
|
+
Copyright © 2020-2021 Kreeti Technologies Pvt. Ltd.
|
1074
|
+
Copyright © 2008-2017 thoughtbot, inc.
|
1075
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -23,7 +23,7 @@ When /^I modify my attachment definition to:$/ do |definition|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
When /^I upload the fixture "([^"]*)"$/ do |filename|
|
26
|
-
|
26
|
+
aruba_run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
|
27
27
|
end
|
28
28
|
|
29
29
|
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
|
@@ -108,3 +108,13 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
108
108
|
expect(columns).not_to include(*expect_columns)
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
# we have to support different versions of aruba, and this method was renamed for 1.0
|
113
|
+
# https://github.com/cucumber/aruba/pull/438
|
114
|
+
def aruba_run_simple(*args)
|
115
|
+
if respond_to?(:run_simple)
|
116
|
+
run_simple(*args)
|
117
|
+
elsif respond_to?(:run_command_and_stop)
|
118
|
+
run_command_and_stop(*args)
|
119
|
+
end
|
120
|
+
end
|
data/gemfiles/4.2.gemfile
CHANGED
data/gemfiles/5.0.gemfile
CHANGED
data/gemfiles/5.1.gemfile
CHANGED
data/gemfiles/5.2.gemfile
CHANGED
data/gemfiles/6.0.gemfile
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry"
|
6
|
+
gem "sqlite3", "~> 1.4", platforms: :ruby
|
7
|
+
gem "aruba", "~> 1.0", ">= 1.0.4"
|
8
|
+
gem "rails", "~> 6.1", ">= 6.1.1"
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem "activerecord-import"
|
12
|
+
gem "bootsnap", require: false
|
13
|
+
gem "builder"
|
14
|
+
gem "listen", "~> 3.0.8"
|
15
|
+
gem "rspec"
|
16
|
+
gem "rubocop", require: false
|
17
|
+
gem "rubocop-rails"
|
18
|
+
gem "sprockets", "3.7.2"
|
19
|
+
end
|
20
|
+
|
21
|
+
gemspec path: "../"
|
data/lib/paperclip.rb
CHANGED
@@ -64,8 +64,7 @@ rescue LoadError
|
|
64
64
|
require "mime/types"
|
65
65
|
end
|
66
66
|
|
67
|
-
require "
|
68
|
-
require "mimemagic/overlay"
|
67
|
+
require "marcel"
|
69
68
|
require "logger"
|
70
69
|
require "terrapin"
|
71
70
|
|
@@ -98,7 +97,8 @@ module Paperclip
|
|
98
97
|
swallow_stderr: true,
|
99
98
|
use_exif_orientation: true,
|
100
99
|
whiny: true,
|
101
|
-
is_windows: Gem.win_platform
|
100
|
+
is_windows: Gem.win_platform?,
|
101
|
+
add_validation_errors_to: :both
|
102
102
|
}
|
103
103
|
end
|
104
104
|
|
@@ -60,15 +60,15 @@ module Paperclip
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def type_from_file_contents
|
63
|
-
|
63
|
+
type_from_marcel || type_from_file_command
|
64
64
|
rescue Errno::ENOENT => e
|
65
65
|
Paperclip.log("Error while determining content type: #{e}")
|
66
66
|
SENSIBLE_DEFAULT
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
70
|
-
@
|
71
|
-
|
69
|
+
def type_from_marcel
|
70
|
+
@type_from_marcel ||= File.open(@filepath) do |file|
|
71
|
+
Marcel::Magic.by_magic(file).try(:type)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -9,8 +9,8 @@ module Paperclip
|
|
9
9
|
REGEXP = /\Ahttps?:\/\//.freeze
|
10
10
|
|
11
11
|
def initialize(target, options = {})
|
12
|
-
escaped =
|
13
|
-
super(URI(target ==
|
12
|
+
escaped = Paperclip::UrlGenerator.escape(target)
|
13
|
+
super(URI(target == Paperclip::UrlGenerator.unescape(target) ? escaped : target), options)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -50,10 +50,20 @@ module Paperclip
|
|
50
50
|
"index.html"
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
if RUBY_VERSION < '2.5'
|
54
|
+
def download_content
|
55
|
+
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
|
55
56
|
|
56
|
-
|
57
|
+
# rubocop:disable Security/Open
|
58
|
+
open(@target, options)
|
59
|
+
# rubocop:enable Security/Open
|
60
|
+
end
|
61
|
+
else
|
62
|
+
def download_content
|
63
|
+
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
|
64
|
+
|
65
|
+
URI.open(@target, options)
|
66
|
+
end
|
57
67
|
end
|
58
68
|
|
59
69
|
def copy_to_tempfile(src)
|