kt-paperclip 5.4.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +3 -0
  3. data/.hound.yml +27 -32
  4. data/.travis.yml +23 -2
  5. data/Appraisals +17 -0
  6. data/Gemfile +9 -7
  7. data/NEWS +21 -0
  8. data/README.md +27 -37
  9. data/Rakefile +29 -21
  10. data/UPGRADING +3 -3
  11. data/features/basic_integration.feature +4 -0
  12. data/features/migration.feature +10 -51
  13. data/features/step_definitions/attachment_steps.rb +12 -12
  14. data/features/step_definitions/html_steps.rb +5 -5
  15. data/features/step_definitions/rails_steps.rb +29 -9
  16. data/features/step_definitions/s3_steps.rb +3 -3
  17. data/features/step_definitions/web_steps.rb +5 -6
  18. data/features/support/env.rb +4 -4
  19. data/features/support/fakeweb.rb +3 -5
  20. data/features/support/file_helpers.rb +2 -2
  21. data/features/support/paths.rb +4 -4
  22. data/features/support/rails.rb +7 -7
  23. data/features/support/selectors.rb +1 -1
  24. data/gemfiles/4.2.gemfile +7 -4
  25. data/gemfiles/5.0.gemfile +7 -4
  26. data/gemfiles/5.1.gemfile +20 -0
  27. data/gemfiles/5.2.gemfile +20 -0
  28. data/gemfiles/6.0.gemfile +20 -0
  29. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  30. data/lib/paperclip/attachment.rb +102 -104
  31. data/lib/paperclip/attachment_registry.rb +2 -2
  32. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  33. data/lib/paperclip/filename_cleaner.rb +0 -1
  34. data/lib/paperclip/geometry.rb +18 -19
  35. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  36. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  37. data/lib/paperclip/glue.rb +3 -3
  38. data/lib/paperclip/has_attached_file.rb +5 -4
  39. data/lib/paperclip/helpers.rb +3 -3
  40. data/lib/paperclip/interpolations.rb +42 -38
  41. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  42. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  43. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  44. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  45. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
  46. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  47. data/lib/paperclip/io_adapters/registry.rb +1 -1
  48. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  49. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  50. data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
  51. data/lib/paperclip/logger.rb +1 -1
  52. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  53. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  54. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  55. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  56. data/lib/paperclip/matchers.rb +4 -4
  57. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  58. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  59. data/lib/paperclip/processor.rb +13 -6
  60. data/lib/paperclip/processor_helpers.rb +3 -1
  61. data/lib/paperclip/rails_environment.rb +1 -5
  62. data/lib/paperclip/railtie.rb +5 -5
  63. data/lib/paperclip/schema.rb +18 -14
  64. data/lib/paperclip/storage/filesystem.rb +5 -7
  65. data/lib/paperclip/storage/fog.rb +36 -32
  66. data/lib/paperclip/storage/s3.rb +67 -75
  67. data/lib/paperclip/style.rb +3 -6
  68. data/lib/paperclip/tempfile.rb +4 -5
  69. data/lib/paperclip/tempfile_factory.rb +0 -1
  70. data/lib/paperclip/thumbnail.rb +11 -11
  71. data/lib/paperclip/url_generator.rb +5 -12
  72. data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
  73. data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
  74. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  75. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  76. data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
  77. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  78. data/lib/paperclip/validators.rb +12 -13
  79. data/lib/paperclip/version.rb +1 -3
  80. data/lib/paperclip.rb +49 -48
  81. data/lib/tasks/paperclip.rake +23 -24
  82. data/paperclip.gemspec +29 -33
  83. data/shoulda_macros/paperclip.rb +16 -16
  84. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  85. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  86. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  87. data/spec/paperclip/attachment_spec.rb +238 -196
  88. data/spec/paperclip/content_type_detector_spec.rb +11 -12
  89. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  90. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  91. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  92. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  93. data/spec/paperclip/geometry_spec.rb +24 -24
  94. data/spec/paperclip/glue_spec.rb +3 -5
  95. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  96. data/spec/paperclip/integration_spec.rb +111 -77
  97. data/spec/paperclip/interpolations_spec.rb +101 -93
  98. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  99. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  100. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  101. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  102. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  103. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
  104. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  105. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  106. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  107. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  108. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  109. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
  110. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  111. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  112. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  113. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  114. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  115. data/spec/paperclip/meta_class_spec.rb +3 -3
  116. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  117. data/spec/paperclip/paperclip_spec.rb +15 -11
  118. data/spec/paperclip/plural_cache_spec.rb +8 -8
  119. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  120. data/spec/paperclip/processor_spec.rb +8 -8
  121. data/spec/paperclip/rails_environment_spec.rb +7 -10
  122. data/spec/paperclip/rake_spec.rb +39 -39
  123. data/spec/paperclip/schema_spec.rb +57 -53
  124. data/spec/paperclip/storage/filesystem_spec.rb +6 -6
  125. data/spec/paperclip/storage/fog_spec.rb +76 -82
  126. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  127. data/spec/paperclip/storage/s3_spec.rb +585 -583
  128. data/spec/paperclip/style_spec.rb +67 -71
  129. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  130. data/spec/paperclip/thumbnail_spec.rb +68 -67
  131. data/spec/paperclip/url_generator_spec.rb +18 -29
  132. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
  133. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
  134. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  135. data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
  136. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  137. data/spec/paperclip/validators_spec.rb +40 -40
  138. data/spec/spec_helper.rb +21 -23
  139. data/spec/support/assertions.rb +8 -6
  140. data/spec/support/fake_model.rb +1 -2
  141. data/spec/support/fake_rails.rb +1 -1
  142. data/spec/support/matchers/exist.rb +1 -1
  143. data/spec/support/matchers/have_column.rb +1 -1
  144. data/spec/support/mock_url_generator_builder.rb +2 -3
  145. data/spec/support/model_reconstruction.rb +16 -12
  146. data/spec/support/reporting.rb +1 -1
  147. data/spec/support/test_data.rb +2 -2
  148. metadata +49 -105
  149. data/lib/kt-paperclip.rb +0 -1
  150. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -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,36 +1,40 @@
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
 
24
26
  attachment_names.each do |attachment_name|
25
27
  COLUMNS.each_pair do |column_name, column_type|
26
28
  column_options = options.merge(options[column_name.to_sym] || {})
27
- add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options)
29
+ add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
28
30
  end
29
31
  end
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|
@@ -51,7 +55,7 @@ module Paperclip
51
55
  attachment_names.each do |attachment_name|
52
56
  COLUMNS.each_pair do |column_name, column_type|
53
57
  column_options = options.merge(options[column_name.to_sym] || {})
54
- column("#{attachment_name}_#{column_name}", column_type, **column_options)
58
+ column("#{attachment_name}_#{column_name}", column_type, column_options)
55
59
  end
56
60
  end
57
61
  end
@@ -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
@@ -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.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