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
@@ -11,31 +11,32 @@ module Paperclip
11
11
  # greater_than(1024) }
12
12
  # it { should validate_attachment_size(:icon).
13
13
  # in(0..100) }
14
- def validate_attachment_size name
14
+ def validate_attachment_size(name)
15
15
  ValidateAttachmentSizeMatcher.new(name)
16
16
  end
17
17
 
18
18
  class ValidateAttachmentSizeMatcher
19
- def initialize attachment_name
19
+ def initialize(attachment_name)
20
20
  @attachment_name = attachment_name
21
21
  end
22
22
 
23
- def less_than size
23
+ def less_than(size)
24
24
  @high = size
25
25
  self
26
26
  end
27
27
 
28
- def greater_than size
28
+ def greater_than(size)
29
29
  @low = size
30
30
  self
31
31
  end
32
32
 
33
- def in range
34
- @low, @high = range.first, range.last
33
+ def in(range)
34
+ @low = range.first
35
+ @high = range.last
35
36
  self
36
37
  end
37
38
 
38
- def matches? subject
39
+ def matches?(subject)
39
40
  @subject = subject
40
41
  @subject = @subject.new if @subject.class == Class
41
42
  lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high?
@@ -56,7 +57,7 @@ module Paperclip
56
57
 
57
58
  protected
58
59
 
59
- def override_method object, method, &replacement
60
+ def override_method(object, method, &replacement)
60
61
  (class << object; self; end).class_eval do
61
62
  define_method(method, &replacement)
62
63
  end
@@ -64,8 +65,8 @@ module Paperclip
64
65
 
65
66
  def passes_validation_with_size(new_size)
66
67
  file = StringIO.new(".")
67
- override_method(file, :size){ new_size }
68
- override_method(file, :to_tempfile){ file }
68
+ override_method(file, :size) { new_size }
69
+ override_method(file, :to_tempfile) { file }
69
70
 
70
71
  @subject.send(@attachment_name).post_processing = false
71
72
  @subject.send(@attachment_name).assign(file)
@@ -1,7 +1,7 @@
1
- require 'paperclip/matchers/have_attached_file_matcher'
2
- require 'paperclip/matchers/validate_attachment_presence_matcher'
3
- require 'paperclip/matchers/validate_attachment_content_type_matcher'
4
- require 'paperclip/matchers/validate_attachment_size_matcher'
1
+ require "paperclip/matchers/have_attached_file_matcher"
2
+ require "paperclip/matchers/validate_attachment_presence_matcher"
3
+ require "paperclip/matchers/validate_attachment_content_type_matcher"
4
+ require "paperclip/matchers/validate_attachment_size_matcher"
5
5
 
6
6
  module Paperclip
7
7
  module Shoulda
@@ -11,7 +11,7 @@ module Paperclip
11
11
  end
12
12
 
13
13
  def spoofed?
14
- if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch?
14
+ if has_name? && media_type_mismatch? && mapping_override_mismatch?
15
15
  Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_content_type} from Headers, #{content_types_from_name.map(&:to_s)} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.")
16
16
  true
17
17
  else
@@ -30,22 +30,24 @@ module Paperclip
30
30
  end
31
31
 
32
32
  def media_type_mismatch?
33
- supplied_type_mismatch? || calculated_type_mismatch?
33
+ extension_type_mismatch? || calculated_type_mismatch?
34
34
  end
35
35
 
36
- def supplied_type_mismatch?
37
- supplied_media_type.present? && !media_types_from_name.include?(supplied_media_type)
36
+ def extension_type_mismatch?
37
+ supplied_media_type.present? &&
38
+ has_extension? &&
39
+ !media_types_from_name.include?(supplied_media_type)
38
40
  end
39
41
 
40
42
  def calculated_type_mismatch?
41
- !media_types_from_name.include?(calculated_media_type)
43
+ supplied_media_type.present? &&
44
+ !calculated_content_type.include?(supplied_media_type)
42
45
  end
43
46
 
44
47
  def mapping_override_mismatch?
45
48
  !Array(mapped_content_type).include?(calculated_content_type)
46
49
  end
47
50
 
48
-
49
51
  def supplied_content_type
50
52
  @content_type
51
53
  end
@@ -71,12 +73,10 @@ module Paperclip
71
73
  end
72
74
 
73
75
  def type_from_file_command
74
- begin
75
- Paperclip.run("file", "-b --mime :file", file: @file.path).
76
- split(/[:;\s]+/).first
77
- rescue Terrapin::CommandLineError
78
- ""
79
- end
76
+ Paperclip.run("file", "-b --mime :file", file: @file.path).
77
+ split(/[:;\s]+/).first
78
+ rescue Terrapin::CommandLineError
79
+ ""
80
80
  end
81
81
 
82
82
  def mapped_content_type
@@ -84,7 +84,7 @@ module Paperclip
84
84
  end
85
85
 
86
86
  def filename_extension
87
- File.extname(@name.to_s.downcase).sub(/^\./, '').to_sym
87
+ File.extname(@name.to_s.downcase).sub(/^\./, "").to_sym
88
88
  end
89
89
  end
90
90
  end
@@ -1,11 +1,11 @@
1
- require 'paperclip/attachment_registry'
2
- require 'set'
1
+ require "paperclip/attachment_registry"
2
+ require "set"
3
3
 
4
4
  module Paperclip
5
5
  class << self
6
6
  attr_writer :registered_attachments_styles_path
7
7
  def registered_attachments_styles_path
8
- @registered_attachments_styles_path ||= Rails.root.join('public/system/paperclip_attachments.yml').to_s
8
+ @registered_attachments_styles_path ||= Rails.root.join("public/system/paperclip_attachments.yml").to_s
9
9
  end
10
10
  end
11
11
 
@@ -18,7 +18,7 @@ module Paperclip
18
18
  private_class_method :get_registered_attachments_styles
19
19
 
20
20
  def self.save_current_attachments_styles!
21
- File.open(Paperclip.registered_attachments_styles_path, 'w') do |f|
21
+ File.open(Paperclip.registered_attachments_styles_path, "w") do |f|
22
22
  YAML.dump(current_attachments_styles, f)
23
23
  end
24
24
  end
@@ -36,7 +36,8 @@ module Paperclip
36
36
  Hash.new.tap do |current_styles|
37
37
  Paperclip::AttachmentRegistry.each_definition do |klass, attachment_name, attachment_attributes|
38
38
  # TODO: is it even possible to take into account Procs?
39
- next if attachment_attributes[:styles].kind_of?(Proc)
39
+ next if attachment_attributes[:styles].is_a?(Proc)
40
+
40
41
  attachment_attributes[:styles].try(:keys).try(:each) do |style_name|
41
42
  klass_sym = klass.to_s.to_sym
42
43
  current_styles[klass_sym] ||= Hash.new
@@ -63,7 +64,11 @@ module Paperclip
63
64
  Hash.new.tap do |missing_styles|
64
65
  current_styles.each do |klass, attachment_definitions|
65
66
  attachment_definitions.each do |attachment_name, styles|
66
- registered = registered_styles[klass][attachment_name] || [] rescue []
67
+ registered = begin
68
+ registered_styles[klass][attachment_name] || []
69
+ rescue StandardError
70
+ []
71
+ end
67
72
  missed = styles - registered
68
73
  if missed.present?
69
74
  klass_sym = klass.to_s.to_sym
@@ -21,29 +21,36 @@ module Paperclip
21
21
  class Processor
22
22
  attr_accessor :file, :options, :attachment
23
23
 
24
- def initialize file, options = {}, attachment = nil
24
+ def initialize(file, options = {}, attachment = nil)
25
25
  @file = file
26
26
  @options = options
27
27
  @attachment = attachment
28
28
  end
29
29
 
30
- def make
31
- end
30
+ def make; end
32
31
 
33
- def self.make file, options = {}, attachment = nil
32
+ def self.make(file, options = {}, attachment = nil)
34
33
  new(file, options, attachment).make
35
34
  end
36
35
 
37
36
  # The convert method runs the convert binary with the provided arguments.
38
37
  # See Paperclip.run for the available options.
39
38
  def convert(arguments = "", local_options = {})
40
- Paperclip.run('convert', arguments, local_options)
39
+ Paperclip.run(
40
+ Paperclip.options[:is_windows] ? "magick convert" : "convert",
41
+ arguments,
42
+ local_options
43
+ )
41
44
  end
42
45
 
43
46
  # The identify method runs the identify binary with the provided arguments.
44
47
  # See Paperclip.run for the available options.
45
48
  def identify(arguments = "", local_options = {})
46
- Paperclip.run('identify', arguments, local_options)
49
+ Paperclip.run(
50
+ Paperclip.options[:is_windows] ? "magick identify" : "identify",
51
+ arguments,
52
+ local_options
53
+ )
47
54
  end
48
55
  end
49
56
  end
@@ -26,7 +26,9 @@ module Paperclip
26
26
  file_exists
27
27
  end
28
28
 
29
- raise LoadError, "Could not find the '#{name}' processor in any of these paths: #{directories.join(', ')}" unless required.any?
29
+ unless required.any?
30
+ raise LoadError, "Could not find the '#{name}' processor in any of these paths: #{directories.join(', ')}"
31
+ end
30
32
  end
31
33
  end
32
34
 
@@ -5,11 +5,7 @@ module Paperclip
5
5
  end
6
6
 
7
7
  def get
8
- if rails_exists? && rails_environment_exists?
9
- Rails.env
10
- else
11
- nil
12
- end
8
+ Rails.env if rails_exists? && rails_environment_exists?
13
9
  end
14
10
 
15
11
  private
@@ -1,11 +1,11 @@
1
- require 'paperclip'
2
- require 'paperclip/schema'
1
+ require "paperclip"
2
+ require "paperclip/schema"
3
3
 
4
4
  module Paperclip
5
- require 'rails'
5
+ require "rails"
6
6
 
7
7
  class Railtie < Rails::Railtie
8
- initializer 'paperclip.insert_into_active_record' do |app|
8
+ initializer "paperclip.insert_into_active_record" do |app|
9
9
  ActiveSupport.on_load :active_record do
10
10
  Paperclip::Railtie.insert
11
11
  end
@@ -24,7 +24,7 @@ module Paperclip
24
24
 
25
25
  if defined?(ActiveRecord)
26
26
  Paperclip.options[:logger] = ActiveRecord::Base.logger
27
- ActiveRecord::Base.send(:include, Paperclip::Glue)
27
+ ActiveRecord::Base.include Paperclip::Glue
28
28
  end
29
29
  end
30
30
  end
@@ -1,23 +1,25 @@
1
- require 'active_support/deprecation'
1
+ require "active_support/deprecation"
2
2
 
3
3
  module Paperclip
4
4
  # Provides helper methods that can be used in migrations.
5
5
  module Schema
6
- COLUMNS = {:file_name => :string,
7
- :content_type => :string,
8
- :file_size => :integer,
9
- :updated_at => :datetime}
6
+ COLUMNS = { file_name: :string,
7
+ content_type: :string,
8
+ file_size: :bigint,
9
+ updated_at: :datetime }.freeze
10
10
 
11
- def self.included(base)
12
- ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
13
- ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
14
- ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
15
- ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
11
+ def self.included(_base)
12
+ ActiveRecord::ConnectionAdapters::Table.include TableDefinition
13
+ ActiveRecord::ConnectionAdapters::TableDefinition.include TableDefinition
14
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.include Statements
15
+ ActiveRecord::Migration::CommandRecorder.include CommandRecorder
16
16
  end
17
17
 
18
18
  module Statements
19
19
  def add_attachment(table_name, *attachment_names)
20
- raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration." if attachment_names.empty?
20
+ if attachment_names.empty?
21
+ raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration."
22
+ end
21
23
 
22
24
  options = attachment_names.extract_options!
23
25
 
@@ -30,7 +32,9 @@ module Paperclip
30
32
  end
31
33
 
32
34
  def remove_attachment(table_name, *attachment_names)
33
- raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty?
35
+ if attachment_names.empty?
36
+ raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration."
37
+ end
34
38
 
35
39
  attachment_names.each do |attachment_name|
36
40
  COLUMNS.keys.each do |column_name|
@@ -19,11 +19,10 @@ module Paperclip
19
19
  # saved by paperclip. If you set this to an explicit octal value (0755, 0644, etc) then
20
20
  # that value will be used to set the permissions for an uploaded file. The default is 0666.
21
21
  # If you set :override_file_permissions to false, the chmod will be skipped. This allows
22
- # you to use paperclip on filesystems that don't understand unix file permissions, and has the
22
+ # you to use paperclip on filesystems that don't understand unix file permissions, and has the
23
23
  # added benefit of using the storage directories default umask on those that do.
24
24
  module Filesystem
25
- def self.extended base
26
- end
25
+ def self.extended(base); end
27
26
 
28
27
  def exists?(style_name = default_style)
29
28
  if original_filename
@@ -46,8 +45,8 @@ module Paperclip
46
45
  end
47
46
  end
48
47
  unless @options[:override_file_permissions] == false
49
- resolved_chmod = (@options[:override_file_permissions] & ~0111) || (0666 & ~File.umask)
50
- FileUtils.chmod( resolved_chmod, path(style_name) )
48
+ resolved_chmod = (@options[:override_file_permissions] & ~0o111) || (0o666 & ~File.umask)
49
+ FileUtils.chmod(resolved_chmod, path(style_name))
51
50
  end
52
51
  file.rewind
53
52
  end
@@ -58,7 +57,7 @@ module Paperclip
58
57
  end
59
58
 
60
59
  def flush_deletes #:nodoc:
61
- @queued_for_delete.each do |path|
60
+ @queued_for_delete.uniq.each do |path|
62
61
  begin
63
62
  log("deleting #{path}")
64
63
  FileUtils.rm(path) if File.exist?(path)
@@ -66,7 +65,7 @@ module Paperclip
66
65
  # ignore file-not-found, let everything else pass
67
66
  end
68
67
  begin
69
- while(true)
68
+ loop do
70
69
  path = File.dirname(path)
71
70
  FileUtils.rmdir(path)
72
71
  break if File.exist?(path) # Ruby 1.9.2 does not raise if the removal failed.
@@ -96,6 +95,5 @@ module Paperclip
96
95
  end
97
96
  end
98
97
  end
99
-
100
98
  end
101
99
  end
@@ -19,7 +19,7 @@ module Paperclip
19
19
  # store your files. Remember that the bucket must be unique across
20
20
  # all of Amazon S3. If the bucket does not exist, Paperclip will
21
21
  # attempt to create it.
22
- # * +fog_file*: This can be hash or lambda returning hash. The
22
+ # * +fog_file+: This can be hash or lambda returning hash. The
23
23
  # value is used as base properties for new uploaded file.
24
24
  # * +path+: This is the key under the bucket in which the file will
25
25
  # be stored. The URL will be constructed from the bucket and the
@@ -39,26 +39,30 @@ module Paperclip
39
39
  # { :multipart_chunk_size => 104857600 }
40
40
 
41
41
  module Fog
42
- def self.extended base
43
- begin
44
- require 'fog'
45
- rescue LoadError => e
46
- e.message << " (You may need to install the fog gem)"
47
- raise e
48
- end unless defined?(Fog)
42
+ def self.extended(base)
43
+ unless defined?(Fog)
44
+ begin
45
+ require "fog"
46
+ rescue LoadError => e
47
+ e.message << " (You may need to install the fog gem)"
48
+ raise e
49
+ end
50
+ end
49
51
 
50
52
  base.instance_eval do
51
53
  unless @options[:url].to_s.match(/\A:fog.*url\z/)
52
- @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system\//, '')
53
- @options[:url] = ':fog_public_url'
54
+ @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system\//, "")
55
+ @options[:url] = ":fog_public_url"
56
+ end
57
+ unless Paperclip::Interpolations.respond_to? :fog_public_url
58
+ Paperclip.interpolates(:fog_public_url) do |attachment, style|
59
+ attachment.public_url(style)
60
+ end
54
61
  end
55
- Paperclip.interpolates(:fog_public_url) do |attachment, style|
56
- attachment.public_url(style)
57
- end unless Paperclip::Interpolations.respond_to? :fog_public_url
58
62
  end
59
63
  end
60
64
 
61
- AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\z))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]\z/
65
+ AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\z))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]\z/.freeze
62
66
 
63
67
  def exists?(style = default_style)
64
68
  if original_filename
@@ -101,20 +105,21 @@ module Paperclip
101
105
  end
102
106
 
103
107
  def flush_writes
104
- for style, file in @queued_for_write do
108
+ @queued_for_write.each do |style, file|
105
109
  log("saving #{path(style)}")
106
110
  retried = false
107
111
  begin
108
112
  attributes = fog_file.merge(
109
- :body => file,
110
- :key => path(style),
111
- :public => fog_public(style),
112
- :content_type => file.content_type
113
+ body: file,
114
+ key: path(style),
115
+ public: fog_public(style),
116
+ content_type: file.content_type
113
117
  )
114
118
  attributes.merge!(@options[:fog_options]) if @options[:fog_options]
115
119
  directory.files.create(attributes)
116
120
  rescue Excon::Errors::NotFound
117
121
  raise if retried
122
+
118
123
  retried = true
119
124
  directory.save
120
125
  file.rewind
@@ -130,9 +135,9 @@ module Paperclip
130
135
  end
131
136
 
132
137
  def flush_deletes
133
- for path in @queued_for_delete do
138
+ @queued_for_delete.uniq.each do |path|
134
139
  log("deleting #{path}")
135
- directory.files.new(:key => path).destroy
140
+ directory.files.new(key: path).destroy
136
141
  end
137
142
  @queued_for_delete = []
138
143
  end
@@ -141,10 +146,10 @@ module Paperclip
141
146
  if @options[:fog_host]
142
147
  "#{dynamic_fog_host_for_style(style)}/#{path(style)}"
143
148
  else
144
- if fog_credentials[:provider] == 'AWS'
149
+ if fog_credentials[:provider] == "AWS"
145
150
  "#{scheme}://#{host_name_for_directory}/#{path(style)}"
146
151
  else
147
- directory.files.new(:key => path(style)).public_url
152
+ directory.files.new(key: path(style)).public_url
148
153
  end
149
154
  end
150
155
  end
@@ -162,7 +167,7 @@ module Paperclip
162
167
  expiring_url = url(style_name)
163
168
  end
164
169
 
165
- return expiring_url
170
+ expiring_url
166
171
  end
167
172
 
168
173
  def parse_credentials(creds)
@@ -172,9 +177,10 @@ module Paperclip
172
177
 
173
178
  def copy_to_local_file(style, local_dest_path)
174
179
  log("copying #{path(style)} to local file #{local_dest_path}")
175
- ::File.open(local_dest_path, 'wb') do |local_file|
180
+ ::File.open(local_dest_path, "wb") do |local_file|
176
181
  file = directory.files.get(path(style))
177
182
  return false unless file
183
+
178
184
  local_file.write(file.body)
179
185
  end
180
186
  rescue ::Fog::Errors::Error => e
@@ -185,9 +191,7 @@ module Paperclip
185
191
  private
186
192
 
187
193
  def convert_time(time)
188
- if time.is_a?(Integer)
189
- time = Time.now + time
190
- end
194
+ time = Time.now + time if time.is_a?(Integer)
191
195
  time
192
196
  end
193
197
 
@@ -195,7 +199,7 @@ module Paperclip
195
199
  if @options[:fog_host].respond_to?(:call)
196
200
  @options[:fog_host].call(self)
197
201
  else
198
- (@options[:fog_host] =~ /%d/) ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host]
202
+ @options[:fog_host] =~ /%d/ ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host]
199
203
  end
200
204
  end
201
205
 
@@ -210,9 +214,9 @@ module Paperclip
210
214
  def find_credentials(creds)
211
215
  case creds
212
216
  when File
213
- YAML::load(ERB.new(File.read(creds.path)).result)
217
+ YAML::safe_load(ERB.new(File.read(creds.path)).result)
214
218
  when String, Pathname
215
- YAML::load(ERB.new(File.read(creds)).result)
219
+ YAML::safe_load(ERB.new(File.read(creds)).result)
216
220
  when Hash
217
221
  creds
218
222
  else
@@ -241,7 +245,7 @@ module Paperclip
241
245
  end
242
246
 
243
247
  def scheme
244
- @scheme ||= fog_credentials[:scheme] || 'https'
248
+ @scheme ||= fog_credentials[:scheme] || "https"
245
249
  end
246
250
  end
247
251
  end