carrierwave-mongoid 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 638d1c8b7b6ec017fd506e049a70aae4cbc5d865f3636f59a112fec019b2773b
4
- data.tar.gz: 25bccea5eeb663d2045bb7d5cc63aef878bfed879012c88621021e3a1671d5c9
3
+ metadata.gz: 695a0d096fa1477e3034c1d1e265f43064edd398e33a683ef664e16af964f4f6
4
+ data.tar.gz: 72b97b4845445ef2378dfc565f3f70fd7d151b027fcd42d0e932c35a1027bd46
5
5
  SHA512:
6
- metadata.gz: 2e91e464455cfa5505927ba89e0bdd70cb9135b7842226fbf16d4b216d6254e57fb8f86307c7e360f08419cf857fdf1bf743e2f8274daf178d2f355271b698fc
7
- data.tar.gz: 509158075089695fc731384507d1508db950cb06895f3720ebffdded4955cf12a70c02d1d0141a2866e807742a9d7f3ff01e47d0ef0ee24b9b44de3eb1368c8e
6
+ metadata.gz: e0c6bc4f88cfe2f136c6fa3e2dc99fb94c530ef8c1b85ba9932b36bf82d268a480892f76e063be6163ed98b94764f622161025f13df70a3743bb7ee720e79600
7
+ data.tar.gz: 7087b901685c9f7b09b933aa0ccbc7154d7611ab4b1b0e95042d24c23c1b0f358b71f9b888b27f0c3e3d17c3938ed3ff65db517558cd9b63bd0cb72616b06fd9
@@ -0,0 +1,45 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ matrix:
8
+ mongodb: [4.4]
9
+ ruby: [2.7, 3.0, 3.1]
10
+ gemfile:
11
+ - carrierwave-2.1
12
+ - carrierwave-2.2
13
+ - mongoid-7
14
+ - mongoid-8
15
+ include:
16
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-0.10" }
17
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-0.11" }
18
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-1.1" }
19
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-1.2" }
20
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-1.3" }
21
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-2.0" }
22
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-3" }
23
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-4" }
24
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-5" }
25
+ - { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-6" }
26
+ name: Ruby ${{ matrix.ruby }} with ${{ matrix.gemfile }}
27
+ env:
28
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
29
+ steps:
30
+ - name: Set up MongoDB ${{ matrix.mongodb }}
31
+ uses: supercharge/mongodb-github-action@1.3.0
32
+ with:
33
+ mongodb-version: ${{ matrix.mongodb }}
34
+ - uses: actions/checkout@v2
35
+ - name: Set up Ruby
36
+ uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: ${{ matrix.ruby }}
39
+ bundler-cache: true
40
+ - run: cat /home/runner/work/carrierwave-mongoid/carrierwave-mongoid/vendor/bundle/ruby/3.0.0/extensions/x86_64-linux/3.0.0/mimemagic-0.4.3/gem_make.out
41
+ if: ${{ failure() }}
42
+ - run: cat /home/runner/work/carrierwave-mongoid/carrierwave-mongoid/vendor/bundle/ruby/3.0.0/gems/mimemagic-0.4.3/ext/mimemagic/Rakefile
43
+ if: ${{ failure() }}
44
+ - name: Run tests
45
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # CarrierWave for Mongoid
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/carrierwave-mongoid.svg)](https://rubygems.org/gems/carrierwave-mongoid)
4
- [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave-mongoid.svg)](http://travis-ci.org/carrierwaveuploader/carrierwave-mongoid)
5
- [![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave-mongoid.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave-mongoid)
4
+ [![Build Status](https://github.com/carrierwaveuploader/carrierwave-mongoid/workflows/CI/badge.svg?branch=master)](https://github.com/carrierwaveuploader/carrierwave-mongoid/actions?query=workflow%3ACI)
6
5
  [![Gem Downloads](https://img.shields.io/gem/dt/carrierwave-mongoid.svg)](https://rubygems.org/gems/carrierwave-mongoid)
7
6
 
8
7
  This gem adds support for Mongoid and MongoDB's GridFS to
@@ -230,4 +229,4 @@ class User
230
229
  end
231
230
  ```
232
231
 
233
- You can read more about this [here](https://github.com/carrierwaveuploader/carrierwave/issues#issue/81)
232
+ You can read more about this [here](https://github.com/carrierwaveuploader/carrierwave/issues/81)
@@ -21,11 +21,11 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_dependency "carrierwave", [">= 0.8", "< 3"]
24
- s.add_dependency "mongoid", [">= 3.0", "< 8.0"]
24
+ s.add_dependency "mongoid", [">= 3.0", "< 9.0"]
25
25
  s.add_dependency "mongoid-grid_fs", [">= 1.3", "< 3.0"]
26
26
  s.add_dependency "mime-types", "< 3" if RUBY_VERSION < "2.0" # mime-types 3+ doesn't support ruby 1.9
27
- s.add_development_dependency "rspec", "~>3.4.0"
28
- s.add_development_dependency "rake", "~>11.1.2"
27
+ s.add_development_dependency "rspec", "~> 3.4"
28
+ s.add_development_dependency "rake", ">= 12.3.3"
29
29
  s.add_development_dependency "mini_magick"
30
30
  s.add_development_dependency "pry"
31
31
  end
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave", "~> 1.1.0"
4
+ gem "mongoid", "> 5.0"
4
5
 
5
6
  gemspec path: "../"
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave", "~> 1.2.0"
4
+ gem "mongoid", "> 5.0"
4
5
 
5
6
  gemspec path: "../"
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "carrierwave", "~> 1.3.0"
4
+ gem "mongoid", "> 5.0"
4
5
 
5
6
  gemspec path: "../"
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "carrierwave", [">= 2.0.0.rc", "< 3"]
3
+ gem "carrierwave", "~> 2.0.0"
4
+ gem "mongoid", "> 5.0"
4
5
 
5
6
  gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave", "~> 2.1.0"
4
+ gem "mongoid", "> 5.0"
5
+
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "carrierwave", "~> 2.2.0"
4
+ gem "mongoid", "> 5.0"
5
+
6
+ gemspec path: "../"
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "mongoid", "~> 7.0"
4
- gem "carrierwave", "~> 1.3"
4
+ gem "carrierwave", "~> 2.2"
5
5
 
6
6
  gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid", "~> 8.0"
4
+ gem "carrierwave", "~> 2.2"
5
+
6
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Mongoid
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -109,11 +109,14 @@ module CarrierWave
109
109
 
110
110
  def find_previous_model_for_#{column}
111
111
  if self.embedded?
112
- if self.respond_to?(:__metadata) # Mongoid >= 4.0.0.beta1
113
- ancestors = [[ self.__metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.__metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
114
- else # Mongoid < 4.0.0.beta1
115
- ancestors = [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
116
- end
112
+ ancestors =
113
+ if self.respond_to?(:_association) # Mongoid >= 7.0.0.beta
114
+ [[ self._association.key, self._parent ]].tap { |x| x.unshift([ x.first.last._association.key, x.first.last._parent ]) while x.first.last.embedded? }
115
+ elsif self.respond_to?(:__metadata) # Mongoid >= 4.0.0.beta1 < 7.0.0.beta
116
+ [[ self.__metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.__metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
117
+ else # Mongoid < 4.0.0.beta1
118
+ [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
119
+ end
117
120
  first_parent = ancestors.first.last
118
121
  reloaded_parent = first_parent.class.unscoped.find(first_parent.to_key.first)
119
122
  association = ancestors.inject(reloaded_parent) { |parent,(key,ancestor)| (parent.is_a?(Array) ? parent.find(ancestor.to_key.first) : parent).send(key) }
@@ -141,8 +144,104 @@ module CarrierWave
141
144
  end
142
145
  super(options).merge(hash)
143
146
  end
147
+
148
+ # Reset cached mounter on mongoid reload
149
+ def reload
150
+ @_mounters = nil
151
+ super
152
+ end
144
153
  RUBY
145
154
  end
155
+
156
+ if Gem::Version.new(CarrierWave::VERSION) >= Gem::Version.new('1.0.beta')
157
+ def mount_uploaders(column, uploader = nil, options = {}, &block)
158
+ field (options[:mount_on] || column), type: Array, default: []
159
+
160
+ super
161
+
162
+ alias_method :read_uploader, :read_attribute
163
+ alias_method :write_uploader, :write_attribute
164
+ public :read_uploader
165
+ public :write_uploader
166
+
167
+ include CarrierWave::Validations::ActiveModel
168
+
169
+ validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
170
+ validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
171
+
172
+ before_update :"store_previous_changes_for_#{column}"
173
+ before_save :"write_#{column}_identifier"
174
+ after_save :"store_#{column}!"
175
+ after_save :"remove_previously_stored_#{column}"
176
+ after_destroy :"remove_#{column}!"
177
+
178
+ class_eval <<-RUBY, __FILE__, (__LINE__ + 1)
179
+ def #{column}=(new_files)
180
+ column = _mounter(:#{column}).serialization_column
181
+
182
+ previous_uploader_value = read_uploader(column)
183
+ @_previous_uploader_value_for_#{column} = previous_uploader_value
184
+
185
+ write_uploader(column, []) if self.persisted? && read_uploader(column).nil?
186
+
187
+ send(:"\#{column}_will_change!")
188
+
189
+ super
190
+ end
191
+
192
+ def #{column}_changed?
193
+ changed_attributes.has_key?("#{column}")
194
+ end
195
+
196
+ def remove_#{column}=(value)
197
+ if ['1', true].include?(value)
198
+ column = _mounter(:#{column}).serialization_column
199
+
200
+ send(:"\#{column}_will_change!")
201
+ end
202
+
203
+ super
204
+ end
205
+
206
+ # The default Mongoid attribute_will_change! method is not enough
207
+ # when we want to upload a new file in an existing embedded document.
208
+ # The custom version of that method forces the callbacks to be
209
+ # ran and so does the upload.
210
+ def #{column}_will_change!
211
+ changed_attributes["#{column}"] = ['_new_']
212
+ end
213
+
214
+ def remove_previously_stored_#{column}
215
+ before, after = @_previous_changes_for_#{column}
216
+ # Don't delete if the files had the same name
217
+ return if before.nil? && after.nil?
218
+ # Proceed to remove the file, use the original name instead of '_new_'
219
+ before = @_previous_uploader_value_for_#{column} || before
220
+ _mounter(:#{column}).remove_previous(Array.wrap(before), Array.wrap(after))
221
+ end
222
+
223
+ def serializable_hash(options = nil)
224
+ hash = {}
225
+
226
+ except = options && options[:except] && Array.wrap(options[:except]).map(&:to_s)
227
+ only = options && options[:only] && Array.wrap(options[:only]).map(&:to_s)
228
+
229
+ self.class.uploaders.each do |column, _uploader|
230
+ if (!only && !except) || (only && only.include?(column.to_s)) || (except && !except.include?(column.to_s))
231
+ next if _mounter(column.to_sym).uploaders.blank?
232
+ hash[column.to_s] = _mounter(column.to_sym).uploaders.map(&:serializable_hash)
233
+ end
234
+ end
235
+
236
+ super(options).merge(hash)
237
+ end
238
+
239
+ def store_previous_changes_for_#{column}
240
+ @_previous_changes_for_#{column} = changes[_mounter(:#{column}).serialization_column]
241
+ end
242
+ RUBY
243
+ end
244
+ end
146
245
  end # Mongoid
147
246
  end # CarrierWave
148
247