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 +4 -4
- data/.github/workflows/ci.yml +45 -0
- data/README.md +2 -3
- data/carrierwave-mongoid.gemspec +3 -3
- data/gemfiles/carrierwave-1.1.gemfile +1 -0
- data/gemfiles/carrierwave-1.2.gemfile +1 -0
- data/gemfiles/carrierwave-1.3.gemfile +1 -0
- data/gemfiles/carrierwave-2.0.gemfile +2 -1
- data/gemfiles/carrierwave-2.1.gemfile +6 -0
- data/gemfiles/carrierwave-2.2.gemfile +6 -0
- data/gemfiles/mongoid-7.gemfile +1 -1
- data/gemfiles/mongoid-8.gemfile +6 -0
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/lib/carrierwave/mongoid.rb +104 -5
- data/spec/carrierwave/mongoid/mount_uploaders_spec.rb +1037 -0
- data/spec/mongoid_spec.rb +66 -55
- data/spec/spec_helper.rb +7 -0
- metadata +20 -15
- data/.travis.yml +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695a0d096fa1477e3034c1d1e265f43064edd398e33a683ef664e16af964f4f6
|
4
|
+
data.tar.gz: 72b97b4845445ef2378dfc565f3f70fd7d151b027fcd42d0e932c35a1027bd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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://
|
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
|
232
|
+
You can read more about this [here](https://github.com/carrierwaveuploader/carrierwave/issues/81)
|
data/carrierwave-mongoid.gemspec
CHANGED
@@ -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", "<
|
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
|
28
|
-
s.add_development_dependency "rake", "
|
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
|
data/gemfiles/mongoid-7.gemfile
CHANGED
data/lib/carrierwave/mongoid.rb
CHANGED
@@ -109,11 +109,14 @@ module CarrierWave
|
|
109
109
|
|
110
110
|
def find_previous_model_for_#{column}
|
111
111
|
if self.embedded?
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
|