carrierwave 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35c836a3a970d4f900cc30a3a601199a629a8554
4
- data.tar.gz: 22b99a337562f2be3c60731377de38b8a204d73f
3
+ metadata.gz: e37b68386a3a7becb2363f72f3ce38e8b9049a9a
4
+ data.tar.gz: 5391ed9991a220136287ad472d243c0ee5164492
5
5
  SHA512:
6
- metadata.gz: f4602848d9c82f60537acb7e3cfaa0ca7bdffe0a0d737224b62400e52c52277109ee1090aa148755ba5ba84f11fa5cdd11bc4209c533cf5c1df7475feda2ad66
7
- data.tar.gz: 95e296300604fc0d41013302cd667d5713f56cb5faa64e5f2ff4d43708e04fdd59c1df6c55414848f526f5eb56618923de9d2a177fb5e2f49be62b383e95b085
6
+ metadata.gz: 2cfc444237e06625db981b6a502847d9a64bd52dc7a7fd4a5189ffc878914fdf7f252d504b54b49d13cb63b2c7d90afdbabaee3b6fb482a3c8bcec49546a51da
7
+ data.tar.gz: 637ee1e7a31c735ff3b9fd7035e7cc897e8acfc610eadeb8c96de778c9b8c64d4a9bcb2e80fe1ed63454e35a029a8ea8224eb3022a748f8a8caa134b9f2048c3
data/README.md CHANGED
@@ -4,8 +4,8 @@ This gem provides a simple and extremely flexible way to upload files from Ruby
4
4
  It works well with Rack based web applications, such as Ruby on Rails.
5
5
 
6
6
  [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
7
- [![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
8
- [![git.legal](https://git.legal/projects/1363/badge.svg "Number of libraries approved")](https://git.legal/projects/1363)
7
+ [![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
8
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)
9
9
 
10
10
 
11
11
  ## Information
@@ -24,7 +24,7 @@ It works well with Rack based web applications, such as Ruby on Rails.
24
24
  Install the latest release:
25
25
 
26
26
  ```
27
- $ gem install carrierwave -v "1.0.0"
27
+ $ gem install carrierwave
28
28
  ```
29
29
 
30
30
  In Rails, add it to your Gemfile:
@@ -307,7 +307,7 @@ to exactly 200 by 200 pixels.
307
307
 
308
308
  If you would like to crop images to a specific height and width you
309
309
  can use the alternative option of '''resize_to_fill'''. It will make sure
310
- that the width and height specified are filled, only copping
310
+ that the width and height specified are filled, only cropping
311
311
  if the aspect ratio requires it.
312
312
 
313
313
  The uploader could be used like this:
@@ -633,6 +633,8 @@ describe MyUploader do
633
633
  end
634
634
  ```
635
635
 
636
+ If you're looking for minitest asserts, checkout [carrierwave_asserts](https://github.com/hcfairbanks/carrierwave_asserts).
637
+
636
638
  Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well.
637
639
  Processing can be enabled for a single version by setting the processing flag on the version like so:
638
640
 
@@ -667,13 +669,14 @@ CarrierWave.configure do |config|
667
669
  config.fog_provider = 'fog/aws' # required
668
670
  config.fog_credentials = {
669
671
  provider: 'AWS', # required
670
- aws_access_key_id: 'xxx', # required
671
- aws_secret_access_key: 'yyy', # required
672
+ aws_access_key_id: 'xxx', # required unless using use_iam_profile
673
+ aws_secret_access_key: 'yyy', # required unless using use_iam_profile
674
+ use_iam_profile: true, # optional, defaults to false
672
675
  region: 'eu-west-1', # optional, defaults to 'us-east-1'
673
676
  host: 's3.example.com', # optional, defaults to nil
674
677
  endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
675
678
  }
676
- config.fog_directory = 'name_of_directory' # required
679
+ config.fog_directory = 'name_of_bucket' # required
677
680
  config.fog_public = false # optional, defaults to true
678
681
  config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
679
682
  end
@@ -61,6 +61,13 @@ module CarrierWave
61
61
  e.message << " (You may need to install the mini_magick gem)"
62
62
  raise e
63
63
  end
64
+
65
+ prepend Module.new {
66
+ def initialize(*)
67
+ super
68
+ @format = nil
69
+ end
70
+ }
64
71
  end
65
72
 
66
73
  module ClassMethods
@@ -67,6 +67,13 @@ module CarrierWave
67
67
  e.message << " (You may need to install the rmagick gem)"
68
68
  raise e
69
69
  end
70
+
71
+ prepend Module.new {
72
+ def initialize(*)
73
+ super
74
+ @format = nil
75
+ end
76
+ }
70
77
  end
71
78
 
72
79
  module ClassMethods
@@ -346,7 +353,7 @@ module CarrierWave
346
353
  frames = ::Magick::ImageList.new
347
354
 
348
355
  image.each_with_index do |frame, index|
349
- frame = yield *[frame, index, options].take(block.arity) if block_given?
356
+ frame = yield(*[frame, index, options].take(block.arity)) if block_given?
350
357
  frames << frame if frame
351
358
  end
352
359
  frames.append(true) if block_given?
@@ -20,7 +20,7 @@ module CarrierWave
20
20
  #
21
21
  class SanitizedFile
22
22
 
23
- attr_accessor :file
23
+ attr_reader :file
24
24
 
25
25
  class << self
26
26
  attr_writer :sanitize_regexp
@@ -32,6 +32,7 @@ module CarrierWave
32
32
 
33
33
  def initialize(file)
34
34
  self.file = file
35
+ @content = nil
35
36
  end
36
37
 
37
38
  ##
@@ -7,6 +7,10 @@ module CarrierWave
7
7
  # pretty much it.
8
8
  #
9
9
  class File < Abstract
10
+ def initialize(*)
11
+ super
12
+ @cache_called = nil
13
+ end
10
14
 
11
15
  ##
12
16
  # Move the file to the uploader's store path.
@@ -266,7 +266,7 @@ module CarrierWave
266
266
  end
267
267
 
268
268
  def initialize(uploader, base, path)
269
- @uploader, @base, @path = uploader, base, path
269
+ @uploader, @base, @path, @content_type = uploader, base, path, nil
270
270
  end
271
271
 
272
272
  ##
@@ -276,6 +276,16 @@ module CarrierWave
276
276
  #
277
277
  # [String] contents of file
278
278
  def read
279
+ file_body = file.body
280
+
281
+ return if file_body.nil?
282
+ return file_body unless file_body.is_a?(::File)
283
+
284
+ # Fog::Storage::XXX::File#body could return the source file which was upoloaded to the remote server.
285
+ read_source_file(file_body) if ::File.exist?(file_body.path)
286
+
287
+ # If the source file doesn't exist, the remote content is read
288
+ @file = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
279
289
  file.body
280
290
  end
281
291
 
@@ -313,7 +323,7 @@ module CarrierWave
313
323
  fog_file = new_file.to_file
314
324
  @content_type ||= new_file.content_type
315
325
  @file = directory.files.create({
316
- :body => (fog_file ? fog_file : new_file).read,
326
+ :body => fog_file ? fog_file : new_file.read,
317
327
  :content_type => @content_type,
318
328
  :key => path,
319
329
  :public => @uploader.fog_public
@@ -458,6 +468,17 @@ module CarrierWave
458
468
  def acl_header
459
469
  {'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'}
460
470
  end
471
+
472
+ def read_source_file(file_body)
473
+ return unless ::File.exist?(file_body.path)
474
+
475
+ begin
476
+ file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's already closed
477
+ file_body.read
478
+ ensure
479
+ file_body.close
480
+ end
481
+ end
461
482
  end
462
483
 
463
484
  end # Fog
@@ -43,6 +43,15 @@ module CarrierWave
43
43
  class Base
44
44
  attr_reader :file
45
45
 
46
+ ##
47
+ # Workaround for class_attribute malfunction when used with Module#prepend
48
+ #
49
+ if RUBY_VERSION < '2.1.0'
50
+ def self.singleton_class?
51
+ !ancestors.include? self
52
+ end
53
+ end
54
+
46
55
  include CarrierWave::Uploader::Configuration
47
56
  include CarrierWave::Uploader::Callbacks
48
57
  include CarrierWave::Uploader::Proxy
@@ -117,12 +117,14 @@ module CarrierWave
117
117
 
118
118
  def add_config(name)
119
119
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
120
+ @#{name} = nil
121
+
120
122
  def self.eager_load_fog(fog_credentials)
121
123
  # see #1198. This will hopefully no longer be necessary after fog 2.0
122
124
  require self.fog_provider
123
125
  require 'carrierwave/storage/fog'
124
126
  Fog::Storage.new(fog_credentials) if fog_credentials.present?
125
- end
127
+ end unless defined? eager_load_fog
126
128
 
127
129
  def self.#{name}(value=nil)
128
130
  @#{name} = value if value
@@ -13,6 +13,7 @@ module CarrierWave
13
13
  def initialize(uri, remote_headers = {})
14
14
  @uri = uri
15
15
  @remote_headers = remote_headers
16
+ @file = nil
16
17
  end
17
18
 
18
19
  def original_filename
@@ -7,6 +7,15 @@ module CarrierWave
7
7
  include CarrierWave::Uploader::Configuration
8
8
  include CarrierWave::Uploader::Cache
9
9
 
10
+ included do
11
+ prepend Module.new {
12
+ def initialize(*)
13
+ super
14
+ @file, @filename, @cache_id = nil
15
+ end
16
+ }
17
+ end
18
+
10
19
  ##
11
20
  # Override this in your Uploader to change the filename.
12
21
  #
@@ -19,6 +19,13 @@ module CarrierWave
19
19
  after :remove, :remove_versions!
20
20
  after :retrieve_from_cache, :retrieve_versions_from_cache!
21
21
  after :retrieve_from_store, :retrieve_versions_from_store!
22
+
23
+ prepend Module.new {
24
+ def initialize(*)
25
+ super
26
+ @versions = nil
27
+ end
28
+ }
22
29
  end
23
30
 
24
31
  module ClassMethods
@@ -77,7 +84,7 @@ module CarrierWave
77
84
  # value from the parent class unless explicitly overwritten
78
85
  def self.enable_processing(value=nil)
79
86
  self.enable_processing = value if value
80
- if !@enable_processing.nil?
87
+ if defined?(@enable_processing) && !@enable_processing.nil?
81
88
  @enable_processing
82
89
  else
83
90
  superclass.enable_processing
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -123,19 +123,61 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: fog
126
+ name: fog-aws
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 1.28.0
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 1.28.0
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fog-google
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "<="
144
+ - !ruby/object:Gem::Version
145
+ version: 0.1.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "<="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.1.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: fog-local
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: fog-rackspace
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
139
181
  - !ruby/object:Gem::Dependency
140
182
  name: mini_magick
141
183
  requirement: !ruby/object:Gem::Requirement
@@ -243,8 +285,6 @@ files:
243
285
  - lib/carrierwave/uploader/extension_blacklist.rb
244
286
  - lib/carrierwave/uploader/extension_whitelist.rb
245
287
  - lib/carrierwave/uploader/file_size.rb
246
- - lib/carrierwave/uploader/magic_mime_blacklist.rb
247
- - lib/carrierwave/uploader/magic_mime_whitelist.rb
248
288
  - lib/carrierwave/uploader/mountable.rb
249
289
  - lib/carrierwave/uploader/processing.rb
250
290
  - lib/carrierwave/uploader/proxy.rb
@@ -1,94 +0,0 @@
1
- module CarrierWave
2
- module Uploader
3
-
4
- ##
5
- # This modules validates the content type of a file with the use of
6
- # ruby-filemagic gem and a blacklist regular expression. If you want
7
- # to use this, you'll need to require this file:
8
- #
9
- # require 'carrierwave/uploader/magic_mime_blacklist'
10
- #
11
- # And then include it in your uploader:
12
- #
13
- # class MyUploader < CarrierWave::Uploader::Base
14
- # include CarrierWave::Uploader::MagicMimeBlacklist
15
- #
16
- # def blacklist_mime_type_pattern
17
- # /image\//
18
- # end
19
- # end
20
- #
21
- module MagicMimeBlacklist
22
- extend ActiveSupport::Concern
23
-
24
- included do
25
- begin
26
- require "filemagic"
27
- rescue LoadError => e
28
- e.message << " (You may need to install the ruby-filemagic gem)"
29
- raise e
30
- end
31
-
32
- before :cache, :check_blacklist_pattern!
33
- end
34
-
35
- ##
36
- # Override this method in your uploader to provide a black list pattern (regexp)
37
- # of content-types which are prohibited to be uploaded.
38
- # Compares the file's content-type.
39
- #
40
- # === Returns
41
- #
42
- # [Regexp] a black list regexp to match the content_type
43
- #
44
- # === Examples
45
- #
46
- # def blacklist_mime_type_pattern
47
- # /(text|application)\/json/
48
- # end
49
- #
50
- def blacklist_mime_type_pattern; end
51
-
52
- private
53
-
54
- def check_blacklist_pattern!(new_file)
55
- return if blacklist_mime_type_pattern.nil?
56
-
57
- content_type = extract_content_type(new_file)
58
-
59
- if content_type.match(blacklist_mime_type_pattern)
60
- raise CarrierWave::IntegrityError,
61
- I18n.translate(:"errors.messages.mime_type_pattern_black_list_error",
62
- :content_type => content_type)
63
- end
64
- end
65
-
66
- ##
67
- # Extracts the content type of the given file
68
- #
69
- # === Returns
70
- #
71
- # [String] the extracted content type
72
- #
73
- def extract_content_type(new_file)
74
- content_type = nil
75
-
76
- File.open(new_file.path) do |fd|
77
- data = fd.read(1024) || ""
78
- content_type = filemagic.buffer(data)
79
- end
80
-
81
- content_type
82
- end
83
-
84
- ##
85
- # FileMagic object with the MAGIC_MIME_TYPE flag set
86
- #
87
- # @return [FileMagic] a filemagic object
88
- def filemagic
89
- @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
90
- end
91
-
92
- end # MagicMimeblackList
93
- end # Uploader
94
- end # CarrierWave
@@ -1,94 +0,0 @@
1
- module CarrierWave
2
- module Uploader
3
-
4
- ##
5
- # This modules validates the content type of a file with the use of
6
- # ruby-filemagic gem and a whitelist regular expression. If you want
7
- # to use this, you'll need to require this file:
8
- #
9
- # require 'carrierwave/uploader/magic_mime_whitelist'
10
- #
11
- # And then include it in your uploader:
12
- #
13
- # class MyUploader < CarrierWave::Uploader::Base
14
- # include CarrierWave::Uploader::MagicMimeWhitelist
15
- #
16
- # def whitelist_mime_type_pattern
17
- # /image\//
18
- # end
19
- # end
20
- #
21
- module MagicMimeWhitelist
22
- extend ActiveSupport::Concern
23
-
24
- included do
25
- begin
26
- require "filemagic"
27
- rescue LoadError => e
28
- e.message << " (You may need to install the ruby-filemagic gem)"
29
- raise e
30
- end
31
-
32
- before :cache, :check_whitelist_pattern!
33
- end
34
-
35
- ##
36
- # Override this method in your uploader to provide a white list pattern (regexp)
37
- # of content-types which are allowed to be uploaded.
38
- # Compares the file's content-type.
39
- #
40
- # === Returns
41
- #
42
- # [Regexp] a white list regexp to match the content_type
43
- #
44
- # === Examples
45
- #
46
- # def whitelist_mime_type_pattern
47
- # /(text|application)\/json/
48
- # end
49
- #
50
- def whitelist_mime_type_pattern; end
51
-
52
- private
53
-
54
- def check_whitelist_pattern!(new_file)
55
- return if whitelist_mime_type_pattern.nil?
56
-
57
- content_type = extract_content_type(new_file)
58
-
59
- if !content_type.match(whitelist_mime_type_pattern)
60
- raise CarrierWave::IntegrityError,
61
- I18n.translate(:"errors.messages.mime_type_pattern_white_list_error",
62
- :content_type => content_type)
63
- end
64
- end
65
-
66
- ##
67
- # Extracts the content type of the given file
68
- #
69
- # === Returns
70
- #
71
- # [String] the extracted content type
72
- #
73
- def extract_content_type(new_file)
74
- content_type = nil
75
-
76
- File.open(new_file.path) do |fd|
77
- data = fd.read(1024) || ""
78
- content_type = filemagic.buffer(data)
79
- end
80
-
81
- content_type
82
- end
83
-
84
- ##
85
- # FileMagic object with the MAGIC_MIME_TYPE flag set
86
- #
87
- # @return [FileMagic] a filemagic object
88
- def filemagic
89
- @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
90
- end
91
-
92
- end # MagicMimeWhiteList
93
- end # Uploader
94
- end # CarrierWave