kt-paperclip 6.4.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/.hound.yml +3 -1057
  4. data/.rubocop.yml +1059 -1
  5. data/.travis.yml +5 -5
  6. data/Appraisals +6 -0
  7. data/CONTRIBUTING.md +4 -5
  8. data/Gemfile +2 -2
  9. data/NEWS +32 -0
  10. data/README.md +8 -7
  11. data/features/step_definitions/attachment_steps.rb +11 -1
  12. data/gemfiles/4.2.gemfile +1 -1
  13. data/gemfiles/5.0.gemfile +1 -1
  14. data/gemfiles/5.1.gemfile +1 -1
  15. data/gemfiles/5.2.gemfile +1 -1
  16. data/gemfiles/6.0.gemfile +1 -1
  17. data/gemfiles/6.1.gemfile +21 -0
  18. data/gemfiles/7.0.gemfile +21 -0
  19. data/lib/paperclip/attachment.rb +1 -1
  20. data/lib/paperclip/content_type_detector.rb +10 -5
  21. data/lib/paperclip/geometry_detector_factory.rb +1 -1
  22. data/lib/paperclip/glue.rb +3 -2
  23. data/lib/paperclip/interpolations.rb +6 -2
  24. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  25. data/lib/paperclip/locales/gd.yml +20 -0
  26. data/lib/paperclip/media_type_spoof_detector.rb +4 -1
  27. data/lib/paperclip/schema.rb +1 -1
  28. data/lib/paperclip/storage/filesystem.rb +1 -1
  29. data/lib/paperclip/storage/fog.rb +1 -1
  30. data/lib/paperclip/storage/s3.rb +18 -4
  31. data/lib/paperclip/validators/attachment_content_type_validator.rb +1 -1
  32. data/lib/paperclip/validators/attachment_file_name_validator.rb +2 -2
  33. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  34. data/lib/paperclip/validators/attachment_size_validator.rb +3 -2
  35. data/lib/paperclip/version.rb +1 -1
  36. data/lib/paperclip.rb +1 -2
  37. data/paperclip.gemspec +3 -3
  38. data/spec/paperclip/content_type_detector_spec.rb +7 -0
  39. data/spec/paperclip/geometry_detector_spec.rb +9 -0
  40. data/spec/paperclip/geometry_spec.rb +16 -4
  41. data/spec/paperclip/glue_spec.rb +21 -0
  42. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  43. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  44. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  45. data/spec/paperclip/media_type_spoof_detector_spec.rb +10 -4
  46. data/spec/paperclip/paperclip_spec.rb +1 -1
  47. data/spec/paperclip/storage/filesystem_spec.rb +23 -0
  48. data/spec/paperclip/storage/fog_spec.rb +46 -0
  49. data/spec/paperclip/storage/s3_spec.rb +179 -47
  50. data/spec/paperclip/validators_spec.rb +21 -6
  51. data/spec/support/fixtures/sample.xlsm +0 -0
  52. metadata +121 -11
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.2
5
4
  - 2.3
6
5
  - 2.4
7
6
  - 2.5
@@ -25,18 +24,19 @@ 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.2.gemfile
33
- rvm: 2.2
34
- - gemfile: gemfiles/6.0.gemfile
35
- rvm: 2.2
36
32
  - gemfile: gemfiles/6.0.gemfile
37
33
  rvm: 2.3
38
34
  - gemfile: gemfiles/6.0.gemfile
39
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
40
  - gemfile: gemfiles/4.2.gemfile
41
41
  rvm: 2.7
42
42
  - gemfile: gemfiles/5.0.gemfile
data/Appraisals CHANGED
@@ -22,3 +22,9 @@ appraise "6.0" do
22
22
  gem "sqlite3", "~> 1.4", platforms: :ruby
23
23
  gem "rails", "~> 6.0.0"
24
24
  end
25
+
26
+ appraise "6.1" do
27
+ gem "sqlite3", "~> 1.4", platforms: :ruby
28
+ gem "aruba", "~> 1.0", ">= 1.0.4"
29
+ gem "rails", "~> 6.1", ">= 6.1.1"
30
+ end
data/CONTRIBUTING.md CHANGED
@@ -10,8 +10,7 @@ Here's a quick guide for contributing:
10
10
 
11
11
  1. Fork the repo.
12
12
 
13
- 1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
14
- (./README.md#image-processor) of the README.
13
+ 1. Make sure you have ImageMagick and Ghostscript installed. See [this section](./README.md#image-processor) of the README.
15
14
 
16
15
  1. Run the tests. We only take pull requests with passing tests, and it's great
17
16
  to know that you have a clean slate: `bundle && bundle exec rake`
@@ -78,9 +77,9 @@ Syntax
78
77
 
79
78
  * Two spaces, no tabs.
80
79
  * No trailing whitespace. Blank lines should not have any space.
81
- * Prefer &&/|| over and/or.
82
- * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
83
- * a = b and not a=b.
80
+ * Prefer `&&` instead of `and` ; prefer `||` instead of `or`.
81
+ * Use `MyClass.my_method(my_arg)` instead of `MyClass.my_method( my_arg )` or `MyClass.my_method my_arg`.
82
+ * `a = b` rather than `a=b` .
84
83
  * Follow the conventions you see used in the source already.
85
84
 
86
85
  And in case we didn't emphasize it enough: we love tests!
data/Gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
- gem "rubocop", require: false
15
+ # Hound only supports certain versions of Rubocop -- 1.22.1 is currently the most recent one supported.
16
+ gem "rubocop", "1.22.1", require: false
17
17
  gem "rubocop-rails"
18
18
  gem "sprockets", "3.7.2"
19
19
  end
data/NEWS CHANGED
@@ -1,3 +1,35 @@
1
+ [UNRELEASED]
2
+ * Improvement: Support file extension names both as symbols and strings for :content_type_mappings
3
+ * Issue file delete only once per unique style when nullifying attachment or destroying an object. Avoids triggering a rate limit error on Google Cloud Storage.
4
+
5
+ 7.0.0 (2021-05-28)
6
+ * Replace `mimemagic` gem with `marcel` due to licensing issues. See https://github.com/kreeti/kt-paperclip/pull/54 for details and limitations
7
+
8
+ 6.4.1 (2021-01-30)
9
+ * Improvement: Use URI.open in ruby > 2.5 (PR #45)
10
+
11
+ 6.4.0 (2020-12-14)
12
+ * Improvement: Fix Ruby 2.7 method & syntax deprecation warnings (#38)
13
+
14
+ 6.3.0 (2020-08-10)
15
+ * Feature: Add validation_errors_to option - customize copying of errors (#26)
16
+ * Stability: Dropped support for ruby 2.1
17
+
18
+ 6.2.2 (2020-02-18)
19
+ * Bugfix: Add support for Aliases in S3 credentials YAML (accidentally removed during 6.2.0 upgrade).
20
+
21
+ 6.2.1 (2020-01-30)
22
+
23
+ * Bugfix: Auto-loading of the gem code (necessitated due to change in gem name).
24
+
25
+ 6.2.0 (2020-01-23):
26
+
27
+ * Bugfix: Don't do post-processing on invalid attachments (#16).
28
+ * Improvement: Use AWS::S3 built in download_file method (#9).
29
+ * Stability: Rubocop recommended syntax updates (#10, #11, #13, #14).
30
+ * Stability: Testing - replace mocha and bourne with rspec mocks (#6).
31
+ * Stability: Fix test suite to run with Rails 5 and Rails 6 (#19, #20, #7).
32
+
1
33
  6.1.0 (2018-07-27):
2
34
 
3
35
  * BUGFIX: Don't double-encode URLs (Roderick Monje).
data/README.md CHANGED
@@ -90,7 +90,7 @@ Requirements
90
90
 
91
91
  ### Ruby and Rails
92
92
 
93
- Paperclip now requires Ruby version **>= 2.2** and Rails version **>= 4.2**
93
+ Paperclip now requires Ruby version **>= 2.3** and Rails version **>= 4.2**
94
94
  (only if you're going to use Paperclip with Ruby on Rails).
95
95
 
96
96
  ### Image Processor
@@ -171,7 +171,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
171
171
  Include the gem in your Gemfile:
172
172
 
173
173
  ```ruby
174
- gem "kt-paperclip", "~> 6.3"
174
+ gem "kt-paperclip", "~> 6.4", ">= 6.4.1"
175
175
  ```
176
176
 
177
177
  Or, if you want to get the latest, you can get master from the main paperclip repository:
@@ -592,9 +592,9 @@ Storage
592
592
 
593
593
  Paperclip ships with 3 storage adapters:
594
594
 
595
- * File Storage
596
- * S3 Storage (via `aws-sdk-s3`)
597
- * Fog Storage
595
+ * File Storage (`storage: :filesystem`)
596
+ * S3 Storage (via `aws-sdk-s3`) (`storage: :s3`)
597
+ * Fog Storage (`storage: :fog`)
598
598
 
599
599
  If you would like to use Paperclip with another storage, you can install these
600
600
  gems along side with Paperclip:
@@ -1070,5 +1070,6 @@ Thank you to all [the contributors](https://github.com/kreeti/kt-paperclip/graph
1070
1070
  License
1071
1071
  -------
1072
1072
 
1073
- Paperclip is Copyright © 2008-2017 thoughtbot, inc. It is free software, and may be
1074
- redistributed under the terms specified in the MIT-LICENSE file.
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
- run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
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
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.0.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.1.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.2.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/6.0.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
@@ -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: "../"
@@ -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", "~> 7.0.0"
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: "../"
@@ -38,7 +38,7 @@ module Paperclip
38
38
  end
39
39
 
40
40
  attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny,
41
- :options, :interpolator, :source_file_options
41
+ :options, :interpolator, :source_file_options, :queued_for_delete
42
42
  attr_accessor :post_processing
43
43
 
44
44
  # Creates an Attachment object. +name+ is the name of the attachment,
@@ -60,16 +60,21 @@ module Paperclip
60
60
  end
61
61
 
62
62
  def type_from_file_contents
63
- type_from_mime_magic || type_from_file_command
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 type_from_mime_magic
70
- @type_from_mime_magic ||= File.open(@filepath) do |file|
71
- MimeMagic.by_magic(file).try(:type)
72
- end
69
+ def type_from_marcel
70
+ return @type_from_marcel if defined? @type_from_marcel
71
+
72
+ @type_from_marcel = Marcel::MimeType.for Pathname.new(@filepath),
73
+ name: @filepath
74
+ # Marcel::MineType returns 'application/octet-stream' if it can't find
75
+ # a valid type.
76
+ @type_from_marcel = nil if @type_from_marcel == SENSIBLE_DEFAULT
77
+ @type_from_marcel
73
78
  end
74
79
 
75
80
  def type_from_file_command
@@ -7,7 +7,7 @@ module Paperclip
7
7
 
8
8
  def make
9
9
  geometry = GeometryParser.new(geometry_string.strip).make
10
- geometry || raise(Errors::NotIdentifiedByImageMagickError.new)
10
+ geometry || raise(Errors::NotIdentifiedByImageMagickError.new("Could not identify image size"))
11
11
  end
12
12
 
13
13
  private
@@ -4,14 +4,15 @@ require "paperclip/schema"
4
4
 
5
5
  module Paperclip
6
6
  module Glue
7
+ LOCALE_PATHS = Dir.glob("#{File.dirname(__FILE__)}/locales/*.{rb,yml}")
8
+
7
9
  def self.included(base)
8
10
  base.extend ClassMethods
9
11
  base.send :include, Callbacks
10
12
  base.send :include, Validators
11
13
  base.send :include, Schema if defined? ActiveRecord::Base
12
14
 
13
- locale_path = Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}")
14
- I18n.load_path += locale_path unless I18n.load_path.include?(locale_path)
15
+ I18n.load_path += LOCALE_PATHS unless (LOCALE_PATHS - I18n.load_path).empty?
15
16
  end
16
17
  end
17
18
  end
@@ -54,10 +54,14 @@ module Paperclip
54
54
  # Returns the interpolated URL. Will raise an error if the url itself
55
55
  # contains ":url" to prevent infinite recursion. This interpolation
56
56
  # is used in the default :path to ease default specifications.
57
- RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, '')}:#{__LINE__ + 3}"
58
57
  def url(attachment, style_name)
59
- raise Errors::InfiniteInterpolationError if caller.any? { |b| b.index(RIGHT_HERE) }
58
+ if Thread.current.thread_variable_get(:kt_paperclip_no_recursion)
59
+ raise Errors::InfiniteInterpolationError
60
+ end
61
+ Thread.current.thread_variable_set(:kt_paperclip_no_recursion, true)
60
62
  attachment.url(style_name, timestamp: false, escape: false)
63
+ ensure
64
+ Thread.current.thread_variable_set(:kt_paperclip_no_recursion, false)
61
65
  end
62
66
 
63
67
  # Returns the timestamp as defined by the <attachment>_updated_at field
@@ -50,10 +50,20 @@ module Paperclip
50
50
  "index.html"
51
51
  end
52
52
 
53
- def download_content
54
- options = { read_timeout: Paperclip.options[:read_timeout] }.compact
53
+ if RUBY_VERSION < '2.5'
54
+ def download_content
55
+ options = { read_timeout: Paperclip.options[:read_timeout] }.compact
55
56
 
56
- self.open(@target, options)
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)
@@ -0,0 +1,20 @@
1
+ gd:
2
+ errors:
3
+ messages:
4
+ in_between: "– feumaidh seo a bhith eadar %{min} ’s %{max}"
5
+ spoofed_media_type: "– tha susbaint ann nach eil a-rèir na chaidh aithris"
6
+
7
+ number:
8
+ human:
9
+ storage_units:
10
+ format: "%n %u"
11
+ units:
12
+ byte:
13
+ one: "bhaidht"
14
+ two: "bhaidht"
15
+ few: "baidhtean"
16
+ other: "baidht"
17
+ kb: "KB"
18
+ mb: "MB"
19
+ gb: "GB"
20
+ tb: "TB"
@@ -76,11 +76,14 @@ module Paperclip
76
76
  Paperclip.run("file", "-b --mime :file", file: @file.path).
77
77
  split(/[:;\s]+/).first
78
78
  rescue Terrapin::CommandLineError
79
+ Paperclip.log("Problem getting type from `file` command. Possible that `file` doesn't exist on this system. Content Type validations don't work without this.")
80
+
79
81
  ""
80
82
  end
81
83
 
82
84
  def mapped_content_type
83
- Paperclip.options[:content_type_mappings][filename_extension]
85
+ content_type_mappings = Paperclip.options[:content_type_mappings]
86
+ content_type_mappings[filename_extension] || content_type_mappings[filename_extension.to_s]
84
87
  end
85
88
 
86
89
  def filename_extension
@@ -6,7 +6,7 @@ module Paperclip
6
6
  COLUMNS = { file_name: :string,
7
7
  content_type: :string,
8
8
  file_size: :bigint,
9
- updated_at: :datetime }.freeze
9
+ updated_at: :datetime }
10
10
 
11
11
  def self.included(_base)
12
12
  ActiveRecord::ConnectionAdapters::Table.include TableDefinition
@@ -57,7 +57,7 @@ module Paperclip
57
57
  end
58
58
 
59
59
  def flush_deletes #:nodoc:
60
- @queued_for_delete.each do |path|
60
+ @queued_for_delete.uniq.each do |path|
61
61
  begin
62
62
  log("deleting #{path}")
63
63
  FileUtils.rm(path) if File.exist?(path)
@@ -135,7 +135,7 @@ module Paperclip
135
135
  end
136
136
 
137
137
  def flush_deletes
138
- @queued_for_delete.each do |path|
138
+ @queued_for_delete.uniq.each do |path|
139
139
  log("deleting #{path}")
140
140
  directory.files.new(key: path).destroy
141
141
  end
@@ -137,6 +137,9 @@ module Paperclip
137
137
  @s3_headers = {}
138
138
  merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)
139
139
 
140
+ @s3_acl_enabled = @options[:s3_acl_enabled]
141
+ @s3_acl_enabled = true if @s3_acl_enabled.nil?
142
+
140
143
  @s3_storage_class = set_storage_class(@options[:s3_storage_class])
141
144
 
142
145
  @s3_server_side_encryption = "AES256"
@@ -359,9 +362,12 @@ module Paperclip
359
362
  log("saving #{path(style)}")
360
363
  write_options = {
361
364
  content_type: file.content_type,
362
- acl: s3_permissions(style)
363
365
  }
364
366
 
367
+ if @s3_acl_enabled
368
+ write_options[:acl] = s3_permissions(style)
369
+ end
370
+
365
371
  # add storage class for this style if defined
366
372
  storage_class = s3_storage_class(style)
367
373
  write_options.merge!(storage_class: storage_class) if storage_class
@@ -403,7 +409,7 @@ module Paperclip
403
409
  end
404
410
 
405
411
  def flush_deletes #:nodoc:
406
- @queued_for_delete.each do |path|
412
+ @queued_for_delete.uniq.each do |path|
407
413
  begin
408
414
  log("deleting #{path}")
409
415
  s3_bucket.object(path.sub(%r{\A/}, "")).delete
@@ -427,9 +433,9 @@ module Paperclip
427
433
  def find_credentials(creds)
428
434
  case creds
429
435
  when File
430
- YAML::safe_load(ERB.new(File.read(creds.path)).result, [], [], true)
436
+ load_credentials_from_file(creds.path)
431
437
  when String, Pathname
432
- YAML::safe_load(ERB.new(File.read(creds)).result, [], [], true)
438
+ load_credentials_from_file(creds)
433
439
  when Hash
434
440
  creds
435
441
  when NilClass
@@ -439,6 +445,14 @@ module Paperclip
439
445
  end
440
446
  end
441
447
 
448
+ def load_credentials_from_file(path)
449
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0")
450
+ YAML::safe_load(ERB.new(File.read(path)).result, aliases: true)
451
+ else
452
+ YAML::safe_load(ERB.new(File.read(path)).result, [], [], true)
453
+ end
454
+ end
455
+
442
456
  def use_secure_protocol?(style_name)
443
457
  s3_protocol(style_name) == "https"
444
458
  end
@@ -47,7 +47,7 @@ module Paperclip
47
47
  end
48
48
 
49
49
  def mark_invalid(record, attribute, types)
50
- record.errors.add attribute, :invalid, options.merge(types: types.join(", "))
50
+ record.errors.add attribute, :invalid, **options.merge(types: types.join(", "))
51
51
  end
52
52
 
53
53
  def allowed_types
@@ -27,7 +27,7 @@ module Paperclip
27
27
  [:both, :base].include?(options[:add_validation_errors_to])
28
28
 
29
29
  record.errors[attribute].each do |error|
30
- record.errors.add base_attribute, error
30
+ record.errors.add(base_attribute, error)
31
31
  end
32
32
 
33
33
  record.errors.delete(attribute) if options[:add_validation_errors_to] == :base
@@ -43,7 +43,7 @@ module Paperclip
43
43
  end
44
44
 
45
45
  def mark_invalid(record, attribute, patterns)
46
- record.errors.add attribute, :invalid, options.merge(names: patterns.join(", "))
46
+ record.errors.add attribute, :invalid, **options.merge(names: patterns.join(", "))
47
47
  end
48
48
 
49
49
  def allowed
@@ -4,7 +4,7 @@ module Paperclip
4
4
  module Validators
5
5
  class AttachmentPresenceValidator < ActiveModel::EachValidator
6
6
  def validate_each(record, attribute, _value)
7
- record.errors.add(attribute, :blank, options) if record.send("#{attribute}_file_name").blank?
7
+ record.errors.add(attribute, :blank, **options) if record.send("#{attribute}_file_name").blank?
8
8
  end
9
9
 
10
10
  def self.helper_method_name
@@ -35,11 +35,12 @@ module Paperclip
35
35
  options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
36
36
  option_value = option_value.call(record) if option_value.is_a?(Proc)
37
37
  option_value = extract_option_value(option, option_value)
38
+ operator = ActiveModel::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
38
39
 
39
- unless value.send(CHECKS[option], option_value)
40
+ unless value.send(operator, option_value)
40
41
  error_message_key = options[:in] ? :in_between : option
41
42
  error_attrs.each do |error_attr_name|
42
- record.errors.add(error_attr_name, error_message_key, filtered_options(value).merge(
43
+ record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
43
44
  min: min_value_in_human_size(record),
44
45
  max: max_value_in_human_size(record),
45
46
  count: human_size(option_value)
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "6.4.0" unless defined?(Paperclip::VERSION)
2
+ VERSION = "7.2.1" unless defined?(Paperclip::VERSION)
3
3
  end
data/lib/paperclip.rb CHANGED
@@ -64,8 +64,7 @@ rescue LoadError
64
64
  require "mime/types"
65
65
  end
66
66
 
67
- require "mimemagic"
68
- require "mimemagic/overlay"
67
+ require "marcel"
69
68
  require "logger"
70
69
  require "terrapin"
71
70
 
data/paperclip.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.author = "Surendra Singhi"
9
9
  s.email = ["ssinghi@kreeti.com"]
10
- s.homepage = "https://github.com/kreeti/paperclip"
10
+ s.homepage = "https://github.com/kreeti/kt-paperclip"
11
11
  s.summary = "File attachments as attributes for ActiveRecord"
12
12
  s.description = "Easy upload management for ActiveRecord"
13
13
  s.license = "MIT"
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
21
21
 
22
22
  s.requirements << "ImageMagick"
23
- s.required_ruby_version = ">= 2.2.0"
23
+ s.required_ruby_version = ">= 2.3.0"
24
24
 
25
25
  s.add_dependency("activemodel", ">= 4.2.0")
26
26
  s.add_dependency("activesupport", ">= 4.2.0")
27
27
  s.add_dependency("mime-types")
28
- s.add_dependency("mimemagic", "~> 0.3.0")
28
+ s.add_dependency("marcel", "~> 1.0.1")
29
29
  s.add_dependency("terrapin", "~> 0.6.0")
30
30
 
31
31
  s.add_development_dependency("activerecord", ">= 4.2.0")
@@ -7,6 +7,13 @@ describe Paperclip::ContentTypeDetector do
7
7
  Paperclip::ContentTypeDetector.new(file.path).detect
8
8
  end
9
9
 
10
+ it 'returns a more specific content type based on the filename if it matches
11
+ multiple content types' do
12
+ file = File.new(fixture_file('sample.xlsm'))
13
+ assert_equal 'application/vnd.ms-excel.sheet.macroenabled.12',
14
+ Paperclip::ContentTypeDetector.new(file.path).detect
15
+ end
16
+
10
17
  it "gives a sensible default when the name is empty" do
11
18
  assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
12
19
  end
@@ -35,4 +35,13 @@ describe Paperclip::GeometryDetector do
35
35
  Paperclip.options[:use_exif_orientation] = true
36
36
  end
37
37
  end
38
+
39
+ it "raises an exception with a message when the file is not an image" do
40
+ file = fixture_file("text.txt")
41
+ factory = Paperclip::GeometryDetector.new(file)
42
+
43
+ expect do
44
+ factory.make
45
+ end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError, "Could not identify image size")
46
+ end
38
47
  end