paperclip 4.3.7 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +5 -16
- data/.travis.yml +15 -12
- data/Appraisals +4 -8
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +3 -8
- data/LICENSE +1 -1
- data/NEWS +105 -31
- data/README.md +239 -153
- data/Rakefile +1 -1
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +3 -2
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -28
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +3 -5
- data/gemfiles/{3.2.gemfile → 5.0.gemfile} +4 -6
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +13 -12
- data/lib/paperclip/attachment.rb +25 -14
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +2 -2
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations.rb +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +17 -14
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +3 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/schema.rb +2 -8
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +20 -13
- data/lib/paperclip/storage/s3.rb +87 -58
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -10
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +72 -18
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +18 -1
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +48 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +15 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +31 -0
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +357 -190
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +38 -35
- data/spec/paperclip/url_generator_spec.rb +54 -43
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +6 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +66 -58
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/4.1.gemfile +0 -19
- data/lib/paperclip/deprecations.rb +0 -42
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/paperclip/deprecations_spec.rb +0 -65
- data/spec/support/deprecations.rb +0 -9
- data/spec/support/rails_helpers.rb +0 -7
@@ -1,15 +1,15 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class HttpUrlProxyAdapter < UriAdapter
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
String === target && target =~ REGEXP
|
6
|
+
end
|
7
|
+
end
|
3
8
|
|
4
9
|
REGEXP = /\Ahttps?:\/\//
|
5
10
|
|
6
|
-
def initialize(target)
|
7
|
-
super(URI(target))
|
11
|
+
def initialize(target, options = {})
|
12
|
+
super(URI(URI.escape(target)), options)
|
8
13
|
end
|
9
|
-
|
10
14
|
end
|
11
15
|
end
|
12
|
-
|
13
|
-
Paperclip.io_adapters.register Paperclip::HttpUrlProxyAdapter do |target|
|
14
|
-
String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP
|
15
|
-
end
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class IdentityAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register Paperclip::IdentityAdapter.new do |target|
|
5
|
+
Paperclip.io_adapters.registered?(target)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
5
10
|
end
|
6
|
-
end
|
7
|
-
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
def new(target, _)
|
13
|
+
target
|
14
|
+
end
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
18
|
+
Paperclip::IdentityAdapter.register
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class NilAdapter < AbstractAdapter
|
3
|
-
def
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
target.nil? || ((Paperclip::Attachment === target) && !target.present?)
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
9
|
+
def initialize(_target, _options = {}); end
|
10
|
+
|
6
11
|
def original_filename
|
7
12
|
""
|
8
13
|
end
|
@@ -19,7 +24,7 @@ module Paperclip
|
|
19
24
|
true
|
20
25
|
end
|
21
26
|
|
22
|
-
def read(*
|
27
|
+
def read(*_args)
|
23
28
|
nil
|
24
29
|
end
|
25
30
|
|
@@ -29,6 +34,4 @@ module Paperclip
|
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
Paperclip.
|
33
|
-
target.nil? || ( (Paperclip::Attachment === target) && !target.present? )
|
34
|
-
end
|
37
|
+
Paperclip::NilAdapter.register
|
@@ -12,6 +12,10 @@ module Paperclip
|
|
12
12
|
@registered_handlers << [block, handler_class]
|
13
13
|
end
|
14
14
|
|
15
|
+
def unregister(handler_class)
|
16
|
+
@registered_handlers.reject! { |_, klass| klass == handler_class }
|
17
|
+
end
|
18
|
+
|
15
19
|
def handler_for(target)
|
16
20
|
@registered_handlers.each do |tester, handler|
|
17
21
|
return handler if tester.call(target)
|
@@ -25,8 +29,8 @@ module Paperclip
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def for(target)
|
29
|
-
handler_for(target).new(target)
|
32
|
+
def for(target, options = {})
|
33
|
+
handler_for(target).new(target, options)
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class StringioAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
StringIO === target
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
5
11
|
cache_current_values
|
6
12
|
end
|
7
13
|
|
@@ -24,10 +30,7 @@ module Paperclip
|
|
24
30
|
destination.rewind
|
25
31
|
destination
|
26
32
|
end
|
27
|
-
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
Paperclip.
|
32
|
-
StringIO === target
|
33
|
-
end
|
36
|
+
Paperclip::StringioAdapter.register
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class UploadedFileAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
target.class.name.include?("UploadedFile")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
5
11
|
cache_current_values
|
6
12
|
|
7
13
|
if @target.respond_to?(:tempfile)
|
@@ -24,7 +30,7 @@ module Paperclip
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def content_type_detector
|
27
|
-
self.class.content_type_detector
|
33
|
+
self.class.content_type_detector || Paperclip::ContentTypeDetector
|
28
34
|
end
|
29
35
|
|
30
36
|
def determine_content_type
|
@@ -37,6 +43,4 @@ module Paperclip
|
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
40
|
-
Paperclip.
|
41
|
-
target.class.name.include?("UploadedFile")
|
42
|
-
end
|
46
|
+
Paperclip::UploadedFileAdapter.register
|
@@ -1,11 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "open-uri"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
class UriAdapter < AbstractAdapter
|
5
5
|
attr_writer :content_type
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def self.register
|
8
|
+
Paperclip.io_adapters.register self do |target|
|
9
|
+
target.is_a?(URI)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(target, options = {})
|
14
|
+
super
|
9
15
|
@content = download_content
|
10
16
|
cache_current_values
|
11
17
|
@tempfile = copy_to_tempfile(@content)
|
@@ -17,8 +23,7 @@ module Paperclip
|
|
17
23
|
self.content_type = content_type_from_content || "text/html"
|
18
24
|
|
19
25
|
self.original_filename = filename_from_content_disposition ||
|
20
|
-
filename_from_path ||
|
21
|
-
default_filename
|
26
|
+
filename_from_path || default_filename
|
22
27
|
@size = @content.size
|
23
28
|
end
|
24
29
|
|
@@ -29,9 +34,9 @@ module Paperclip
|
|
29
34
|
end
|
30
35
|
|
31
36
|
def filename_from_content_disposition
|
32
|
-
if @content.meta.
|
33
|
-
@content.meta["content-disposition"].
|
34
|
-
|
37
|
+
if @content.meta.key?("content-disposition")
|
38
|
+
matches = @content.meta["content-disposition"].match(/filename="([^"]*)"/)
|
39
|
+
matches[1] if matches
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
@@ -44,11 +49,13 @@ module Paperclip
|
|
44
49
|
end
|
45
50
|
|
46
51
|
def download_content
|
47
|
-
|
52
|
+
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
|
53
|
+
|
54
|
+
open(@target, **options)
|
48
55
|
end
|
49
56
|
|
50
57
|
def copy_to_tempfile(src)
|
51
|
-
while data = src.read(16*1024)
|
58
|
+
while data = src.read(16 * 1024)
|
52
59
|
destination.write(data)
|
53
60
|
end
|
54
61
|
src.close
|
@@ -57,7 +64,3 @@ module Paperclip
|
|
57
64
|
end
|
58
65
|
end
|
59
66
|
end
|
60
|
-
|
61
|
-
Paperclip.io_adapters.register Paperclip::UriAdapter do |target|
|
62
|
-
target.kind_of?(URI)
|
63
|
-
end
|
@@ -40,9 +40,9 @@ module Paperclip
|
|
40
40
|
|
41
41
|
def failure_message
|
42
42
|
"#{expected_attachment}\n".tap do |message|
|
43
|
-
message << accepted_types_and_failures
|
43
|
+
message << accepted_types_and_failures.to_s
|
44
44
|
message << "\n\n" if @allowed_types.present? && @rejected_types.present?
|
45
|
-
message << rejected_types_and_failures
|
45
|
+
message << rejected_types_and_failures.to_s
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -55,7 +55,7 @@ module Paperclip
|
|
55
55
|
def accepted_types_and_failures
|
56
56
|
if @allowed_types.present?
|
57
57
|
"Accept content types: #{@allowed_types.join(", ")}\n".tap do |message|
|
58
|
-
if @missing_allowed_types.
|
58
|
+
if @missing_allowed_types.present?
|
59
59
|
message << " #{@missing_allowed_types.join(", ")} were rejected."
|
60
60
|
else
|
61
61
|
message << " All were accepted successfully."
|
@@ -66,7 +66,7 @@ module Paperclip
|
|
66
66
|
def rejected_types_and_failures
|
67
67
|
if @rejected_types.present?
|
68
68
|
"Reject content types: #{@rejected_types.join(", ")}\n".tap do |message|
|
69
|
-
if @missing_rejected_types.
|
69
|
+
if @missing_rejected_types.present?
|
70
70
|
message << " #{@missing_rejected_types.join(", ")} were accepted."
|
71
71
|
else
|
72
72
|
message << " All were rejected successfully."
|
@@ -72,8 +72,9 @@ module Paperclip
|
|
72
72
|
|
73
73
|
def type_from_file_command
|
74
74
|
begin
|
75
|
-
Paperclip.run("file", "-b --mime :file", :
|
76
|
-
|
75
|
+
Paperclip.run("file", "-b --mime :file", file: @file.path).
|
76
|
+
split(/[:;\s]+/).first
|
77
|
+
rescue Terrapin::CommandLineError
|
77
78
|
""
|
78
79
|
end
|
79
80
|
end
|
data/lib/paperclip/processor.rb
CHANGED
@@ -7,13 +7,14 @@ module Paperclip
|
|
7
7
|
# Processors are required to be defined inside the Paperclip module and
|
8
8
|
# are also required to be a subclass of Paperclip::Processor. There is
|
9
9
|
# only one method you *must* implement to properly be a subclass:
|
10
|
-
# #make, but #initialize may also be of use.
|
10
|
+
# #make, but #initialize may also be of use. #initialize accepts 3
|
11
11
|
# arguments: the file that will be operated on (which is an instance of
|
12
12
|
# File), a hash of options that were defined in has_attached_file's
|
13
|
-
# style hash, and the Paperclip::Attachment itself.
|
13
|
+
# style hash, and the Paperclip::Attachment itself. These are set as
|
14
|
+
# instance variables that can be used within `#make`.
|
14
15
|
#
|
15
|
-
#
|
16
|
-
#
|
16
|
+
# #make must return an instance of File (Tempfile is acceptable) which
|
17
|
+
# contains the results of the processing.
|
17
18
|
#
|
18
19
|
# See Paperclip.run for more information about using command-line
|
19
20
|
# utilities from within Processors.
|
data/lib/paperclip/schema.rb
CHANGED
@@ -12,10 +12,7 @@ module Paperclip
|
|
12
12
|
ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
|
13
13
|
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
|
14
14
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
|
15
|
-
|
16
|
-
if defined?(ActiveRecord::Migration::CommandRecorder) # Rails 3.1+
|
17
|
-
ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
|
18
|
-
end
|
15
|
+
ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
|
19
16
|
end
|
20
17
|
|
21
18
|
module Statements
|
@@ -35,11 +32,8 @@ module Paperclip
|
|
35
32
|
def remove_attachment(table_name, *attachment_names)
|
36
33
|
raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty?
|
37
34
|
|
38
|
-
options = attachment_names.extract_options!
|
39
|
-
|
40
35
|
attachment_names.each do |attachment_name|
|
41
|
-
COLUMNS.
|
42
|
-
column_options = options.merge(options[column_name.to_sym] || {})
|
36
|
+
COLUMNS.keys.each do |column_name|
|
43
37
|
remove_column(table_name, "#{attachment_name}_#{column_name}")
|
44
38
|
end
|
45
39
|
end
|
@@ -37,7 +37,7 @@ module Paperclip
|
|
37
37
|
@queued_for_write.each do |style_name, file|
|
38
38
|
FileUtils.mkdir_p(File.dirname(path(style_name)))
|
39
39
|
begin
|
40
|
-
|
40
|
+
move_file(file.path, path(style_name))
|
41
41
|
rescue SystemCallError
|
42
42
|
File.open(path(style_name), "wb") do |new_file|
|
43
43
|
while chunk = file.read(16 * 1024)
|
@@ -46,7 +46,7 @@ module Paperclip
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
unless @options[:override_file_permissions] == false
|
49
|
-
resolved_chmod = (@options[:override_file_permissions]
|
49
|
+
resolved_chmod = (@options[:override_file_permissions] & ~0111) || (0666 & ~File.umask)
|
50
50
|
FileUtils.chmod( resolved_chmod, path(style_name) )
|
51
51
|
end
|
52
52
|
file.rewind
|
@@ -84,6 +84,17 @@ module Paperclip
|
|
84
84
|
def copy_to_local_file(style, local_dest_path)
|
85
85
|
FileUtils.cp(path(style), local_dest_path)
|
86
86
|
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def move_file(src, dest)
|
91
|
+
# Support hardlinked files
|
92
|
+
if File.identical?(src, dest)
|
93
|
+
File.unlink(src)
|
94
|
+
else
|
95
|
+
FileUtils.mv(src, dest)
|
96
|
+
end
|
97
|
+
end
|
87
98
|
end
|
88
99
|
|
89
100
|
end
|
@@ -48,7 +48,7 @@ module Paperclip
|
|
48
48
|
end unless defined?(Fog)
|
49
49
|
|
50
50
|
base.instance_eval do
|
51
|
-
unless @options[:url].to_s.match(/\A:fog.*url\
|
51
|
+
unless @options[:url].to_s.match(/\A:fog.*url\z/)
|
52
52
|
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system\//, '')
|
53
53
|
@options[:url] = ':fog_public_url'
|
54
54
|
end
|
@@ -58,7 +58,7 @@ module Paperclip
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\
|
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/
|
62
62
|
|
63
63
|
def exists?(style = default_style)
|
64
64
|
if original_filename
|
@@ -86,11 +86,14 @@ module Paperclip
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def fog_public(style = default_style)
|
89
|
-
if @options.
|
90
|
-
|
91
|
-
|
89
|
+
if @options.key?(:fog_public)
|
90
|
+
value = @options[:fog_public]
|
91
|
+
if value.respond_to?(:key?) && value.key?(style)
|
92
|
+
value[style]
|
93
|
+
elsif value.respond_to?(:call)
|
94
|
+
value.call(self)
|
92
95
|
else
|
93
|
-
|
96
|
+
value
|
94
97
|
end
|
95
98
|
else
|
96
99
|
true
|
@@ -114,6 +117,7 @@ module Paperclip
|
|
114
117
|
raise if retried
|
115
118
|
retried = true
|
116
119
|
directory.save
|
120
|
+
file.rewind
|
117
121
|
retry
|
118
122
|
ensure
|
119
123
|
file.rewind
|
@@ -170,6 +174,7 @@ module Paperclip
|
|
170
174
|
log("copying #{path(style)} to local file #{local_dest_path}")
|
171
175
|
::File.open(local_dest_path, 'wb') do |local_file|
|
172
176
|
file = directory.files.get(path(style))
|
177
|
+
return false unless file
|
173
178
|
local_file.write(file.body)
|
174
179
|
end
|
175
180
|
rescue ::Fog::Errors::Error => e
|
@@ -180,7 +185,7 @@ module Paperclip
|
|
180
185
|
private
|
181
186
|
|
182
187
|
def convert_time(time)
|
183
|
-
if time.is_a?(
|
188
|
+
if time.is_a?(Integer)
|
184
189
|
time = Time.now + time
|
185
190
|
end
|
186
191
|
time
|
@@ -195,10 +200,10 @@ module Paperclip
|
|
195
200
|
end
|
196
201
|
|
197
202
|
def host_name_for_directory
|
198
|
-
if
|
199
|
-
"#{
|
203
|
+
if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
|
204
|
+
"#{directory_name}.s3.amazonaws.com"
|
200
205
|
else
|
201
|
-
"s3.amazonaws.com/#{
|
206
|
+
"s3.amazonaws.com/#{directory_name}"
|
202
207
|
end
|
203
208
|
end
|
204
209
|
|
@@ -224,13 +229,15 @@ module Paperclip
|
|
224
229
|
end
|
225
230
|
|
226
231
|
def directory
|
227
|
-
|
232
|
+
@directory ||= connection.directories.new(key: directory_name)
|
233
|
+
end
|
234
|
+
|
235
|
+
def directory_name
|
236
|
+
if @options[:fog_directory].respond_to?(:call)
|
228
237
|
@options[:fog_directory].call(self)
|
229
238
|
else
|
230
239
|
@options[:fog_directory]
|
231
240
|
end
|
232
|
-
|
233
|
-
@directory ||= connection.directories.new(:key => dir)
|
234
241
|
end
|
235
242
|
|
236
243
|
def scheme
|