kt-paperclip 5.4.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1055
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +23 -4
  9. data/Appraisals +23 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +10 -7
  12. data/NEWS +52 -0
  13. data/README.md +58 -46
  14. data/Rakefile +29 -21
  15. data/UPGRADING +3 -3
  16. data/features/basic_integration.feature +4 -0
  17. data/features/migration.feature +10 -51
  18. data/features/step_definitions/attachment_steps.rb +23 -13
  19. data/features/step_definitions/html_steps.rb +5 -5
  20. data/features/step_definitions/rails_steps.rb +29 -9
  21. data/features/step_definitions/s3_steps.rb +3 -3
  22. data/features/step_definitions/web_steps.rb +5 -6
  23. data/features/support/env.rb +4 -4
  24. data/features/support/fakeweb.rb +3 -5
  25. data/features/support/file_helpers.rb +2 -2
  26. data/features/support/paths.rb +4 -4
  27. data/features/support/rails.rb +7 -7
  28. data/features/support/selectors.rb +1 -1
  29. data/gemfiles/4.2.gemfile +7 -4
  30. data/gemfiles/5.0.gemfile +7 -4
  31. data/gemfiles/5.1.gemfile +20 -0
  32. data/gemfiles/5.2.gemfile +20 -0
  33. data/gemfiles/6.0.gemfile +20 -0
  34. data/gemfiles/6.1.gemfile +21 -0
  35. data/gemfiles/7.0.gemfile +21 -0
  36. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  37. data/lib/paperclip/attachment.rb +103 -105
  38. data/lib/paperclip/attachment_registry.rb +2 -2
  39. data/lib/paperclip/content_type_detector.rb +10 -5
  40. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  41. data/lib/paperclip/filename_cleaner.rb +0 -1
  42. data/lib/paperclip/geometry.rb +18 -19
  43. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  44. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  45. data/lib/paperclip/glue.rb +3 -3
  46. data/lib/paperclip/has_attached_file.rb +5 -4
  47. data/lib/paperclip/helpers.rb +3 -3
  48. data/lib/paperclip/interpolations.rb +42 -38
  49. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  50. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  51. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  52. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  53. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  54. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  55. data/lib/paperclip/io_adapters/registry.rb +1 -1
  56. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  57. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  58. data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
  59. data/lib/paperclip/logger.rb +1 -1
  60. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  61. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  62. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  63. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  64. data/lib/paperclip/matchers.rb +4 -4
  65. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  66. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  67. data/lib/paperclip/processor.rb +13 -6
  68. data/lib/paperclip/processor_helpers.rb +3 -1
  69. data/lib/paperclip/rails_environment.rb +1 -5
  70. data/lib/paperclip/railtie.rb +5 -5
  71. data/lib/paperclip/schema.rb +16 -12
  72. data/lib/paperclip/storage/filesystem.rb +6 -8
  73. data/lib/paperclip/storage/fog.rb +36 -32
  74. data/lib/paperclip/storage/s3.rb +68 -76
  75. data/lib/paperclip/style.rb +3 -6
  76. data/lib/paperclip/tempfile.rb +4 -5
  77. data/lib/paperclip/tempfile_factory.rb +0 -1
  78. data/lib/paperclip/thumbnail.rb +11 -11
  79. data/lib/paperclip/url_generator.rb +5 -5
  80. data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
  81. data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
  82. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  83. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  84. data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
  85. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  86. data/lib/paperclip/validators.rb +16 -17
  87. data/lib/paperclip/version.rb +1 -3
  88. data/lib/paperclip.rb +49 -48
  89. data/lib/tasks/paperclip.rake +23 -24
  90. data/paperclip.gemspec +29 -33
  91. data/shoulda_macros/paperclip.rb +16 -16
  92. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  93. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  94. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  95. data/spec/paperclip/attachment_spec.rb +238 -196
  96. data/spec/paperclip/content_type_detector_spec.rb +18 -12
  97. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  98. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  99. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  100. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  101. data/spec/paperclip/geometry_spec.rb +24 -24
  102. data/spec/paperclip/glue_spec.rb +3 -5
  103. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  104. data/spec/paperclip/integration_spec.rb +111 -77
  105. data/spec/paperclip/interpolations_spec.rb +101 -93
  106. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  107. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  108. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  109. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  110. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  111. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
  112. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  113. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  114. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  115. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  116. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  117. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
  118. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  119. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  120. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  121. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  122. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  123. data/spec/paperclip/meta_class_spec.rb +3 -3
  124. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  125. data/spec/paperclip/paperclip_spec.rb +15 -11
  126. data/spec/paperclip/plural_cache_spec.rb +8 -8
  127. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  128. data/spec/paperclip/processor_spec.rb +8 -8
  129. data/spec/paperclip/rails_environment_spec.rb +7 -10
  130. data/spec/paperclip/rake_spec.rb +39 -39
  131. data/spec/paperclip/schema_spec.rb +57 -53
  132. data/spec/paperclip/storage/filesystem_spec.rb +29 -6
  133. data/spec/paperclip/storage/fog_spec.rb +122 -82
  134. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  135. data/spec/paperclip/storage/s3_spec.rb +649 -583
  136. data/spec/paperclip/style_spec.rb +67 -71
  137. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  138. data/spec/paperclip/thumbnail_spec.rb +68 -67
  139. data/spec/paperclip/url_generator_spec.rb +18 -19
  140. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
  141. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
  142. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  143. data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
  144. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  145. data/spec/paperclip/validators_spec.rb +61 -46
  146. data/spec/spec_helper.rb +21 -23
  147. data/spec/support/assertions.rb +8 -6
  148. data/spec/support/fake_model.rb +1 -2
  149. data/spec/support/fake_rails.rb +1 -1
  150. data/spec/support/fixtures/aws_s3.yml +13 -0
  151. data/spec/support/fixtures/sample.xlsm +0 -0
  152. data/spec/support/matchers/exist.rb +1 -1
  153. data/spec/support/matchers/have_column.rb +1 -1
  154. data/spec/support/mock_url_generator_builder.rb +2 -3
  155. data/spec/support/model_reconstruction.rb +16 -12
  156. data/spec/support/reporting.rb +1 -1
  157. data/spec/support/test_data.rb +2 -2
  158. metadata +58 -106
  159. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,9 +1,9 @@
1
- require 'active_model/validations/numericality'
1
+ require "active_model/validations/numericality"
2
2
 
3
3
  module Paperclip
4
4
  module Validators
5
5
  class AttachmentSizeValidator < ActiveModel::Validations::NumericalityValidator
6
- AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to]
6
+ AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to].freeze
7
7
 
8
8
  def initialize(options)
9
9
  extract_options(options)
@@ -17,21 +17,34 @@ module Paperclip
17
17
  def validate_each(record, attr_name, value)
18
18
  base_attr_name = attr_name
19
19
  attr_name = "#{attr_name}_file_size".to_sym
20
+
21
+ error_attrs = []
22
+ case options[:add_validation_errors_to]
23
+ when :base
24
+ error_attrs << base_attr_name
25
+ when :attribute
26
+ error_attrs << attr_name
27
+ else
28
+ error_attrs << base_attr_name
29
+ error_attrs << attr_name
30
+ end
31
+
20
32
  value = record.send(:read_attribute_for_validation, attr_name)
21
33
 
22
34
  unless value.blank?
23
35
  options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
24
36
  option_value = option_value.call(record) if option_value.is_a?(Proc)
25
37
  option_value = extract_option_value(option, option_value)
26
-
27
- unless value.send(CHECKS[option], option_value)
38
+ operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
39
+
40
+ unless value.send(operator, option_value)
28
41
  error_message_key = options[:in] ? :in_between : option
29
- [ attr_name, base_attr_name ].each do |error_attr_name|
30
- record.errors.add(error_attr_name, error_message_key, filtered_options(value).merge(
31
- :min => min_value_in_human_size(record),
32
- :max => max_value_in_human_size(record),
33
- :count => human_size(option_value)
34
- ))
42
+ error_attrs.each do |error_attr_name|
43
+ record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
44
+ min: min_value_in_human_size(record),
45
+ max: max_value_in_human_size(record),
46
+ count: human_size(option_value)
47
+ ))
35
48
  end
36
49
  end
37
50
  end
@@ -39,7 +52,7 @@ module Paperclip
39
52
  end
40
53
 
41
54
  def check_validity!
42
- unless (AVAILABLE_CHECKS + [:in]).any? { |argument| options.has_key?(argument) }
55
+ unless (AVAILABLE_CHECKS + [:in]).any? { |argument| options.key?(argument) }
43
56
  raise ArgumentError, "You must pass either :less_than, :greater_than, or :in to the validator"
44
57
  end
45
58
  end
@@ -56,6 +69,10 @@ module Paperclip
56
69
  options[:greater_than_or_equal_to] = range
57
70
  end
58
71
  end
72
+
73
+ unless options.key?(:add_validation_errors_to)
74
+ options[:add_validation_errors_to] = Paperclip.options[:add_validation_errors_to]
75
+ end
59
76
  end
60
77
 
61
78
  def extract_option_value(option, option_value)
@@ -1,4 +1,4 @@
1
- require 'active_model/validations/presence'
1
+ require "active_model/validations/presence"
2
2
 
3
3
  module Paperclip
4
4
  module Validators
@@ -8,6 +8,8 @@ module Paperclip
8
8
  if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename, value.content_type).spoofed?
9
9
  record.errors.add(attribute, :spoofed_media_type)
10
10
  end
11
+
12
+ adapter.tempfile.close(true) if adapter.tempfile
11
13
  end
12
14
  end
13
15
 
@@ -1,12 +1,12 @@
1
- require 'active_model'
2
- require 'active_support/concern'
3
- require 'active_support/core_ext/array/wrap'
4
- require 'paperclip/validators/attachment_content_type_validator'
5
- require 'paperclip/validators/attachment_file_name_validator'
6
- require 'paperclip/validators/attachment_presence_validator'
7
- require 'paperclip/validators/attachment_size_validator'
8
- require 'paperclip/validators/media_type_spoof_detection_validator'
9
- require 'paperclip/validators/attachment_file_type_ignorance_validator'
1
+ require "active_model"
2
+ require "active_support/concern"
3
+ require "active_support/core_ext/array/wrap"
4
+ require "paperclip/validators/attachment_content_type_validator"
5
+ require "paperclip/validators/attachment_file_name_validator"
6
+ require "paperclip/validators/attachment_presence_validator"
7
+ require "paperclip/validators/attachment_size_validator"
8
+ require "paperclip/validators/media_type_spoof_detection_validator"
9
+ require "paperclip/validators/attachment_file_type_ignorance_validator"
10
10
 
11
11
  module Paperclip
12
12
  module Validators
@@ -17,13 +17,13 @@ module Paperclip
17
17
  include HelperMethods
18
18
  end
19
19
 
20
- ::Paperclip::REQUIRED_VALIDATORS = [AttachmentFileNameValidator, AttachmentContentTypeValidator, AttachmentFileTypeIgnoranceValidator]
20
+ ::Paperclip::REQUIRED_VALIDATORS = [AttachmentFileNameValidator, AttachmentContentTypeValidator, AttachmentFileTypeIgnoranceValidator].freeze
21
21
 
22
22
  module ClassMethods
23
- # This method is a shortcut to validator classes that is in
24
- # "Attachment...Validator" format. It is almost the same thing as the
25
- # +validates+ method that shipped with Rails, but this is customized to
26
- # be using with attachment validators. This is helpful when you're using
23
+ # This method is a shortcut to the validator classes that are in
24
+ # "Attachment...Validator" format. It is almost the same as the
25
+ # +validates+ method that ships with Rails, but is customized for
26
+ # use with attachment validators. This is helpful when you're using
27
27
  # multiple attachment validators on a single attachment.
28
28
  #
29
29
  # Example of using the validator:
@@ -39,7 +39,7 @@ module Paperclip
39
39
  if constant.to_s =~ /\AAttachment(.+)Validator\z/
40
40
  validator_kind = $1.underscore.to_sym
41
41
 
42
- if options.has_key?(validator_kind)
42
+ if options.key?(validator_kind)
43
43
  validator_options = options.delete(validator_kind)
44
44
  validator_options = {} if validator_options == true
45
45
  conditional_options = options.slice(:if, :unless)
@@ -64,11 +64,10 @@ module Paperclip
64
64
  def create_validating_before_filter(attribute, validator_class, options)
65
65
  if_clause = options.delete(:if)
66
66
  unless_clause = options.delete(:unless)
67
- send(:"before_#{attribute}_post_process", :if => if_clause, :unless => unless_clause) do |*args|
67
+ send(:"before_#{attribute}_validate", if: if_clause, unless: unless_clause) do |*_args|
68
68
  validator_class.new(options.dup).validate(self)
69
69
  end
70
70
  end
71
-
72
71
  end
73
72
  end
74
73
  end
@@ -1,5 +1,3 @@
1
1
  module Paperclip
2
- unless defined?(Paperclip::VERSION)
3
- VERSION = "5.4.0".freeze
4
- end
2
+ VERSION = "7.1.1" unless defined?(Paperclip::VERSION)
5
3
  end
data/lib/paperclip.rb CHANGED
@@ -25,37 +25,37 @@
25
25
  #
26
26
  # See the +has_attached_file+ documentation for more details.
27
27
 
28
- require 'erb'
29
- require 'digest'
30
- require 'tempfile'
31
- require 'paperclip/version'
32
- require 'paperclip/geometry_parser_factory'
33
- require 'paperclip/geometry_detector_factory'
34
- require 'paperclip/geometry'
35
- require 'paperclip/processor'
36
- require 'paperclip/processor_helpers'
37
- require 'paperclip/tempfile'
38
- require 'paperclip/thumbnail'
39
- require 'paperclip/interpolations/plural_cache'
40
- require 'paperclip/interpolations'
41
- require 'paperclip/tempfile_factory'
42
- require 'paperclip/style'
43
- require 'paperclip/attachment'
44
- require 'paperclip/storage'
45
- require 'paperclip/callbacks'
46
- require 'paperclip/file_command_content_type_detector'
47
- require 'paperclip/media_type_spoof_detector'
48
- require 'paperclip/content_type_detector'
49
- require 'paperclip/glue'
50
- require 'paperclip/errors'
51
- require 'paperclip/missing_attachment_styles'
52
- require 'paperclip/validators'
53
- require 'paperclip/logger'
54
- require 'paperclip/helpers'
55
- require 'paperclip/has_attached_file'
56
- require 'paperclip/attachment_registry'
57
- require 'paperclip/filename_cleaner'
58
- require 'paperclip/rails_environment'
28
+ require "erb"
29
+ require "digest"
30
+ require "tempfile"
31
+ require "paperclip/version"
32
+ require "paperclip/geometry_parser_factory"
33
+ require "paperclip/geometry_detector_factory"
34
+ require "paperclip/geometry"
35
+ require "paperclip/processor"
36
+ require "paperclip/processor_helpers"
37
+ require "paperclip/tempfile"
38
+ require "paperclip/thumbnail"
39
+ require "paperclip/interpolations/plural_cache"
40
+ require "paperclip/interpolations"
41
+ require "paperclip/tempfile_factory"
42
+ require "paperclip/style"
43
+ require "paperclip/attachment"
44
+ require "paperclip/storage"
45
+ require "paperclip/callbacks"
46
+ require "paperclip/file_command_content_type_detector"
47
+ require "paperclip/media_type_spoof_detector"
48
+ require "paperclip/content_type_detector"
49
+ require "paperclip/glue"
50
+ require "paperclip/errors"
51
+ require "paperclip/missing_attachment_styles"
52
+ require "paperclip/validators"
53
+ require "paperclip/logger"
54
+ require "paperclip/helpers"
55
+ require "paperclip/has_attached_file"
56
+ require "paperclip/attachment_registry"
57
+ require "paperclip/filename_cleaner"
58
+ require "paperclip/rails_environment"
59
59
 
60
60
  begin
61
61
  # Use mime/types/columnar if available, for reduced memory usage
@@ -64,12 +64,11 @@ rescue LoadError
64
64
  require "mime/types"
65
65
  end
66
66
 
67
- require 'mimemagic'
68
- require 'mimemagic/overlay'
69
- require 'logger'
70
- require 'terrapin'
67
+ require "marcel"
68
+ require "logger"
69
+ require "terrapin"
71
70
 
72
- require 'paperclip/railtie' if defined?(Rails::Railtie)
71
+ require "paperclip/railtie" if defined?(Rails::Railtie)
73
72
 
74
73
  # The base module that gets included in ActiveRecord::Base. See the
75
74
  # documentation for Paperclip::ClassMethods for more useful information.
@@ -98,6 +97,8 @@ module Paperclip
98
97
  swallow_stderr: true,
99
98
  use_exif_orientation: true,
100
99
  whiny: true,
100
+ is_windows: Gem.win_platform?,
101
+ add_validation_errors_to: :both
101
102
  }
102
103
  end
103
104
 
@@ -200,15 +201,15 @@ module Paperclip
200
201
  end
201
202
 
202
203
  # This stuff needs to be run after Paperclip is defined.
203
- require 'paperclip/io_adapters/registry'
204
- require 'paperclip/io_adapters/abstract_adapter'
205
- require 'paperclip/io_adapters/empty_string_adapter'
206
- require 'paperclip/io_adapters/identity_adapter'
207
- require 'paperclip/io_adapters/file_adapter'
208
- require 'paperclip/io_adapters/stringio_adapter'
209
- require 'paperclip/io_adapters/data_uri_adapter'
210
- require 'paperclip/io_adapters/nil_adapter'
211
- require 'paperclip/io_adapters/attachment_adapter'
212
- require 'paperclip/io_adapters/uploaded_file_adapter'
213
- require 'paperclip/io_adapters/uri_adapter'
214
- require 'paperclip/io_adapters/http_url_proxy_adapter'
204
+ require "paperclip/io_adapters/registry"
205
+ require "paperclip/io_adapters/abstract_adapter"
206
+ require "paperclip/io_adapters/empty_string_adapter"
207
+ require "paperclip/io_adapters/identity_adapter"
208
+ require "paperclip/io_adapters/file_adapter"
209
+ require "paperclip/io_adapters/stringio_adapter"
210
+ require "paperclip/io_adapters/data_uri_adapter"
211
+ require "paperclip/io_adapters/nil_adapter"
212
+ require "paperclip/io_adapters/attachment_adapter"
213
+ require "paperclip/io_adapters/uploaded_file_adapter"
214
+ require "paperclip/io_adapters/uri_adapter"
215
+ require "paperclip/io_adapters/http_url_proxy_adapter"
@@ -1,25 +1,24 @@
1
- require 'paperclip/attachment_registry'
1
+ require "paperclip/attachment_registry"
2
2
 
3
3
  module Paperclip
4
4
  module Task
5
5
  def self.obtain_class
6
- class_name = ENV['CLASS'] || ENV['class']
6
+ class_name = ENV["CLASS"] || ENV["class"]
7
7
  raise "Must specify CLASS" unless class_name
8
+
8
9
  class_name
9
10
  end
10
11
 
11
12
  def self.obtain_attachments(klass)
12
13
  klass = Paperclip.class_for(klass.to_s)
13
- name = ENV['ATTACHMENT'] || ENV['attachment']
14
+ name = ENV["ATTACHMENT"] || ENV["attachment"]
14
15
 
15
16
  attachment_names = Paperclip::AttachmentRegistry.names_for(klass)
16
17
 
17
- if attachment_names.empty?
18
- raise "Class #{klass.name} has no attachments specified"
19
- end
18
+ raise "Class #{klass.name} has no attachments specified" if attachment_names.empty?
20
19
 
21
20
  if name.present? && attachment_names.map(&:to_s).include?(name.to_s)
22
- [ name ]
21
+ [name]
23
22
  else
24
23
  attachment_names
25
24
  end
@@ -33,14 +32,14 @@ end
33
32
 
34
33
  namespace :paperclip do
35
34
  desc "Refreshes both metadata and thumbnails."
36
- task :refresh => ["paperclip:refresh:metadata", "paperclip:refresh:thumbnails"]
35
+ task refresh: ["paperclip:refresh:metadata", "paperclip:refresh:thumbnails"]
37
36
 
38
37
  namespace :refresh do
39
38
  desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma)."
40
- task :thumbnails => :environment do
39
+ task thumbnails: :environment do
41
40
  klass = Paperclip::Task.obtain_class
42
41
  names = Paperclip::Task.obtain_attachments(klass)
43
- styles = (ENV['STYLES'] || ENV['styles'] || '').split(',').map(&:to_sym)
42
+ styles = (ENV["STYLES"] || ENV["styles"] || "").split(",").map(&:to_sym)
44
43
  names.each do |name|
45
44
  Paperclip.each_instance_with_attachment(klass, name) do |instance|
46
45
  attachment = instance.send(name)
@@ -59,7 +58,7 @@ namespace :paperclip do
59
58
  end
60
59
 
61
60
  desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
62
- task :metadata => :environment do
61
+ task metadata: :environment do
63
62
  klass = Paperclip::Task.obtain_class
64
63
  names = Paperclip::Task.obtain_attachments(klass)
65
64
  names.each do |name|
@@ -69,7 +68,7 @@ namespace :paperclip do
69
68
  instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
70
69
  instance.send("#{name}_content_type=", file.content_type.to_s.strip)
71
70
  instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
72
- instance.save(:validate => false)
71
+ instance.save(validate: false)
73
72
  else
74
73
  true
75
74
  end
@@ -78,45 +77,45 @@ namespace :paperclip do
78
77
  end
79
78
 
80
79
  desc "Regenerates missing thumbnail styles for all classes using Paperclip."
81
- task :missing_styles => :environment do
80
+ task missing_styles: :environment do
82
81
  Rails.application.eager_load!
83
82
  Paperclip.missing_attachments_styles.each do |klass, attachment_definitions|
84
83
  attachment_definitions.each do |attachment_name, missing_styles|
85
84
  puts "Regenerating #{klass} -> #{attachment_name} -> #{missing_styles.inspect}"
86
- ENV['CLASS'] = klass.to_s
87
- ENV['ATTACHMENT'] = attachment_name.to_s
88
- ENV['STYLES'] = missing_styles.join(',')
89
- Rake::Task['paperclip:refresh:thumbnails'].execute
85
+ ENV["CLASS"] = klass.to_s
86
+ ENV["ATTACHMENT"] = attachment_name.to_s
87
+ ENV["STYLES"] = missing_styles.join(",")
88
+ Rake::Task["paperclip:refresh:thumbnails"].execute
90
89
  end
91
90
  end
92
91
  Paperclip.save_current_attachments_styles!
93
92
  end
94
93
 
95
94
  desc "Regenerates fingerprints for a given CLASS (and optional ATTACHMENT). Useful when changing digest."
96
- task :fingerprints => :environment do
95
+ task fingerprints: :environment do
97
96
  klass = Paperclip::Task.obtain_class
98
97
  names = Paperclip::Task.obtain_attachments(klass)
99
98
  names.each do |name|
100
99
  Paperclip.each_instance_with_attachment(klass, name) do |instance|
101
100
  attachment = instance.send(name)
102
101
  attachment.assign(attachment)
103
- instance.save(:validate => false)
102
+ instance.save(validate: false)
104
103
  end
105
104
  end
106
105
  end
107
106
  end
108
107
 
109
108
  desc "Cleans out invalid attachments. Useful after you've added new validations."
110
- task :clean => :environment do
109
+ task clean: :environment do
111
110
  klass = Paperclip::Task.obtain_class
112
111
  names = Paperclip::Task.obtain_attachments(klass)
113
112
  names.each do |name|
114
113
  Paperclip.each_instance_with_attachment(klass, name) do |instance|
115
114
  unless instance.valid?
116
- attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
117
- if attributes.any?{ |attribute| instance.errors[attribute].present? }
115
+ attributes = %w(file_size file_name content_type).map { |suffix| "#{name}_#{suffix}".to_sym }
116
+ if attributes.any? { |attribute| instance.errors[attribute].present? }
118
117
  instance.send("#{name}=", nil)
119
- instance.save(:validate => false)
118
+ instance.save(validate: false)
120
119
  end
121
120
  end
122
121
  end
@@ -124,7 +123,7 @@ namespace :paperclip do
124
123
  end
125
124
 
126
125
  desc "find missing attachments. Useful to know which attachments are broken"
127
- task :find_broken_attachments => :environment do
126
+ task find_broken_attachments: :environment do
128
127
  klass = Paperclip::Task.obtain_class
129
128
  names = Paperclip::Task.obtain_attachments(klass)
130
129
  names.each do |name|
data/paperclip.gemspec CHANGED
@@ -1,5 +1,5 @@
1
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
- require 'paperclip/version'
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
+ require "paperclip/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "kt-paperclip"
@@ -14,41 +14,37 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- if File.exist?('UPGRADING')
21
- s.post_install_message = File.read("UPGRADING")
22
- end
20
+ s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
23
21
 
24
22
  s.requirements << "ImageMagick"
25
- s.required_ruby_version = ">= 2.1.0"
23
+ s.required_ruby_version = ">= 2.3.0"
26
24
 
27
- s.add_dependency('activemodel', '>= 4.2.0', '< 6.0')
28
- s.add_dependency('activesupport', '>= 4.2.0', '< 6.0')
29
- s.add_dependency('terrapin', '~> 0.6.0')
30
- s.add_dependency('mime-types')
31
- s.add_dependency('mimemagic', '~> 0.3.8')
25
+ s.add_dependency("activemodel", ">= 4.2.0")
26
+ s.add_dependency("activesupport", ">= 4.2.0")
27
+ s.add_dependency("mime-types")
28
+ s.add_dependency("marcel", "~> 1.0.1")
29
+ s.add_dependency("terrapin", "~> 0.6.0")
32
30
 
33
- s.add_development_dependency('activerecord', '>= 4.2.0', '< 6.0')
34
- s.add_development_dependency('shoulda')
35
- s.add_development_dependency('rspec', '~> 3.0')
36
- s.add_development_dependency('appraisal')
37
- s.add_development_dependency('mocha')
38
- s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
39
- s.add_development_dependency('bourne', '< 1.6')
40
- s.add_development_dependency('cucumber-rails')
41
- s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
42
- s.add_development_dependency('aruba', '~> 0.9.0')
43
- s.add_development_dependency('nokogiri')
44
- s.add_development_dependency('capybara')
45
- s.add_development_dependency('bundler')
46
- s.add_development_dependency('fog-aws')
47
- s.add_development_dependency('fog-local')
48
- s.add_development_dependency('launchy')
49
- s.add_development_dependency('rake')
50
- s.add_development_dependency('fakeweb')
51
- s.add_development_dependency('railties', '>= 4.2.0', '< 6.0')
52
- s.add_development_dependency('generator_spec')
53
- s.add_development_dependency('timecop')
31
+ s.add_development_dependency("activerecord", ">= 4.2.0")
32
+ s.add_development_dependency("appraisal")
33
+ s.add_development_dependency("aruba", "~> 0.9.0")
34
+ s.add_development_dependency("aws-sdk-s3")
35
+ s.add_development_dependency("bundler")
36
+ s.add_development_dependency("capybara")
37
+ s.add_development_dependency("cucumber-expressions")
38
+ s.add_development_dependency("cucumber-rails")
39
+ s.add_development_dependency("fakeweb")
40
+ s.add_development_dependency("fog-aws")
41
+ s.add_development_dependency("fog-local")
42
+ s.add_development_dependency("generator_spec")
43
+ s.add_development_dependency("launchy")
44
+ s.add_development_dependency("nokogiri")
45
+ s.add_development_dependency("railties")
46
+ s.add_development_dependency("rake")
47
+ s.add_development_dependency("rspec", "~> 3.0")
48
+ s.add_development_dependency("shoulda")
49
+ s.add_development_dependency("timecop")
54
50
  end
@@ -1,4 +1,4 @@
1
- require 'paperclip/matchers'
1
+ require "paperclip/matchers"
2
2
 
3
3
  module Paperclip
4
4
  # =Paperclip Shoulda Macros
@@ -13,8 +13,8 @@ module Paperclip
13
13
  # This will test whether you have defined your attachment correctly by
14
14
  # checking for all the required fields exist after the definition of the
15
15
  # attachment.
16
- def should_have_attached_file name
17
- klass = self.name.gsub(/Test$/, '').constantize
16
+ def should_have_attached_file(name)
17
+ klass = self.name.gsub(/Test$/, "").constantize
18
18
  matcher = have_attached_file name
19
19
  should matcher.description do
20
20
  assert_accepts(matcher, klass)
@@ -22,8 +22,8 @@ module Paperclip
22
22
  end
23
23
 
24
24
  # Tests for validations on the presence of the attachment.
25
- def should_validate_attachment_presence name
26
- klass = self.name.gsub(/Test$/, '').constantize
25
+ def should_validate_attachment_presence(name)
26
+ klass = self.name.gsub(/Test$/, "").constantize
27
27
  matcher = validate_attachment_presence name
28
28
  should matcher.description do
29
29
  assert_accepts(matcher, klass)
@@ -34,8 +34,8 @@ module Paperclip
34
34
  # options, :valid and :invalid. Both accept an array of strings. The
35
35
  # strings should be a list of content types which will pass and fail
36
36
  # validation, respectively.
37
- def should_validate_attachment_content_type name, options = {}
38
- klass = self.name.gsub(/Test$/, '').constantize
37
+ def should_validate_attachment_content_type(name, options = {})
38
+ klass = self.name.gsub(/Test$/, "").constantize
39
39
  valid = [options[:valid]].flatten
40
40
  invalid = [options[:invalid]].flatten
41
41
  matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
@@ -50,10 +50,10 @@ module Paperclip
50
50
  # :less_than checks that a file is less than a certain size, :greater_than
51
51
  # checks that a file is more than a certain size, and :in takes a Range or
52
52
  # Array which specifies the lower and upper limits of the file size.
53
- def should_validate_attachment_size name, options = {}
54
- klass = self.name.gsub(/Test$/, '').constantize
53
+ def should_validate_attachment_size(name, options = {})
54
+ klass = self.name.gsub(/Test$/, "").constantize
55
55
  min = options[:greater_than] || (options[:in] && options[:in].first) || 0
56
- max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
56
+ max = options[:less_than] || (options[:in] && options[:in].last) || (1.0 / 0)
57
57
  range = (min..max)
58
58
  matcher = validate_attachment_size(name).in(range)
59
59
  should matcher.description do
@@ -65,17 +65,17 @@ module Paperclip
65
65
  #
66
66
  # @example
67
67
  # stub_paperclip_s3('user', 'avatar', 'png')
68
- def stub_paperclip_s3(model, attachment, extension)
68
+ def stub_paperclip_s3(model, attachment, _extension)
69
69
  definition = model.gsub(" ", "_").classify.constantize.
70
- attachment_definitions[attachment.to_sym]
70
+ attachment_definitions[attachment.to_sym]
71
71
 
72
72
  path = "http://s3.amazonaws.com/:id/#{definition[:path]}"
73
- path.gsub!(/:([^\/\.]+)/) do |match|
73
+ path.gsub!(/:([^\/\.]+)/) do |_match|
74
74
  "([^\/\.]+)"
75
75
  end
76
76
 
77
77
  begin
78
- FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
78
+ FakeWeb.register_uri(:put, Regexp.new(path), body: "OK")
79
79
  rescue NameError
80
80
  raise NameError, "the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
81
81
  end
@@ -104,11 +104,11 @@ module Paperclip
104
104
  end
105
105
 
106
106
  if defined?(ActionDispatch::Integration::Session)
107
- class ActionDispatch::IntegrationTest::Session #:nodoc:
107
+ class ActionDispatch::IntegrationTest::Session #:nodoc:
108
108
  include Paperclip::Shoulda
109
109
  end
110
110
  elsif defined?(ActionController::Integration::Session)
111
- class ActionController::Integration::Session #:nodoc:
111
+ class ActionController::Integration::Session #:nodoc:
112
112
  include Paperclip::Shoulda
113
113
  end
114
114
  end
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe "Attachment Definitions" do
4
- it 'returns all of the attachments on the class' do
4
+ it "returns all of the attachments on the class" do
5
5
  reset_class "Dummy"
6
- Dummy.has_attached_file :avatar, {path: "abc"}
7
- Dummy.has_attached_file :other_attachment, {url: "123"}
6
+ Dummy.has_attached_file :avatar, path: "abc"
7
+ Dummy.has_attached_file :other_attachment, url: "123"
8
8
  Dummy.do_not_validate_attachment_file_type :avatar
9
- expected = {avatar: {path: "abc"}, other_attachment: {url: "123"}}
9
+ expected = { avatar: { path: "abc" }, other_attachment: { url: "123" } }
10
10
 
11
11
  expect(Dummy.attachment_definitions).to eq expected
12
12
  end