carrierwave-mongoid 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -4
- data/carrierwave-mongoid.gemspec +1 -1
- data/gemfiles/carrierwave-2.0.gemfile +5 -0
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/lib/carrierwave/storage/grid_fs.rb +50 -1
- data/spec/storage/grid_fs_spec.rb +24 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 638d1c8b7b6ec017fd506e049a70aae4cbc5d865f3636f59a112fec019b2773b
|
4
|
+
data.tar.gz: 25bccea5eeb663d2045bb7d5cc63aef878bfed879012c88621021e3a1671d5c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e91e464455cfa5505927ba89e0bdd70cb9135b7842226fbf16d4b216d6254e57fb8f86307c7e360f08419cf857fdf1bf743e2f8274daf178d2f355271b698fc
|
7
|
+
data.tar.gz: 509158075089695fc731384507d1508db950cb06895f3720ebffdded4955cf12a70c02d1d0141a2866e807742a9d7f3ff01e47d0ef0ee24b9b44de3eb1368c8e
|
data/.travis.yml
CHANGED
@@ -7,10 +7,10 @@ notifications:
|
|
7
7
|
language: ruby
|
8
8
|
cache: bundler
|
9
9
|
rvm:
|
10
|
-
- 2.3
|
11
|
-
- 2.4
|
12
|
-
- 2.5
|
13
|
-
- 2.6
|
10
|
+
- 2.3
|
11
|
+
- 2.4
|
12
|
+
- 2.5
|
13
|
+
- 2.6
|
14
14
|
|
15
15
|
gemfile:
|
16
16
|
- Gemfile
|
@@ -19,6 +19,7 @@ gemfile:
|
|
19
19
|
- gemfiles/carrierwave-1.1.gemfile
|
20
20
|
- gemfiles/carrierwave-1.2.gemfile
|
21
21
|
- gemfiles/carrierwave-1.3.gemfile
|
22
|
+
- gemfiles/carrierwave-2.0.gemfile
|
22
23
|
- gemfiles/mongoid-3.gemfile
|
23
24
|
- gemfiles/mongoid-4.gemfile
|
24
25
|
- gemfiles/mongoid-5.gemfile
|
data/carrierwave-mongoid.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_dependency "carrierwave", [">= 0.8", "<
|
23
|
+
s.add_dependency "carrierwave", [">= 0.8", "< 3"]
|
24
24
|
s.add_dependency "mongoid", [">= 3.0", "< 8.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
|
@@ -44,7 +44,7 @@ module CarrierWave
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def write(file)
|
47
|
-
grid[
|
47
|
+
grid[path] = file
|
48
48
|
ensure
|
49
49
|
@grid_file = nil
|
50
50
|
end
|
@@ -109,6 +109,55 @@ module CarrierWave
|
|
109
109
|
CarrierWave::Storage::GridFS::File.new(uploader, uploader.store_path(identifier))
|
110
110
|
end
|
111
111
|
|
112
|
+
##
|
113
|
+
# Cache the file in MongoDB's GridFS GridStore
|
114
|
+
#
|
115
|
+
# === Parameters
|
116
|
+
#
|
117
|
+
# [file (CarrierWave::SanitizedFile)] the file to store
|
118
|
+
#
|
119
|
+
# === Returns
|
120
|
+
#
|
121
|
+
# [CarrierWave::SanitizedFile] a sanitized file
|
122
|
+
#
|
123
|
+
def cache!(file)
|
124
|
+
stored = CarrierWave::Storage::GridFS::File.new(uploader, uploader.cache_path)
|
125
|
+
stored.write(file)
|
126
|
+
stored
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Retrieve the cached file from MongoDB's GridFS GridStore
|
131
|
+
#
|
132
|
+
# === Parameters
|
133
|
+
#
|
134
|
+
# [identifier (String)] uniquely identifies a cache file
|
135
|
+
#
|
136
|
+
# === Returns
|
137
|
+
#
|
138
|
+
# [CarrierWave::Storage::GridFS::File] a sanitized file
|
139
|
+
#
|
140
|
+
def retrieve_from_cache!(identifier)
|
141
|
+
CarrierWave::Storage::GridFS::File.new(uploader, uploader.cache_path(identifier))
|
142
|
+
end
|
143
|
+
|
144
|
+
def delete_dir!(path)
|
145
|
+
# do nothing, because there's no such things as 'empty directory'
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Clean old caches
|
150
|
+
#
|
151
|
+
# === Parameters
|
152
|
+
#
|
153
|
+
# [seconds (Integer)] duration in seconds, caches older than this will be deleted
|
154
|
+
#
|
155
|
+
def clean_cache!(seconds)
|
156
|
+
File.grid.namespace.
|
157
|
+
where(filename: /\d+-\d+-\d+(?:-\d+)?\/.+/).
|
158
|
+
and(:filename.lt => (Time.now.utc - seconds).to_i.to_s).
|
159
|
+
delete
|
160
|
+
end
|
112
161
|
end # GridFS
|
113
162
|
end # Storage
|
114
163
|
end # CarrierWave
|
@@ -154,11 +154,12 @@ describe CarrierWave::Storage::GridFS do
|
|
154
154
|
@uploader_class.class_eval{
|
155
155
|
include CarrierWave::MiniMagick
|
156
156
|
storage :grid_fs
|
157
|
+
process resize_to_fill: [200, 200]
|
157
158
|
}
|
158
159
|
|
159
160
|
@versioned = @uploader_class.new
|
160
161
|
|
161
|
-
@
|
162
|
+
@file = File.open(file_path('portrait.jpg'))
|
162
163
|
end
|
163
164
|
|
164
165
|
after do
|
@@ -166,9 +167,30 @@ describe CarrierWave::Storage::GridFS do
|
|
166
167
|
end
|
167
168
|
|
168
169
|
it "resizes the file with out error" do
|
169
|
-
expect { @versioned.
|
170
|
+
expect { @versioned.store! @file }.not_to raise_error
|
170
171
|
end
|
171
172
|
end
|
173
|
+
|
174
|
+
describe "#clean_cache!" do
|
175
|
+
before do
|
176
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
177
|
+
@uploader_class.class_eval{
|
178
|
+
storage :grid_fs
|
179
|
+
}
|
180
|
+
|
181
|
+
file = File.open(file_path('portrait.jpg'))
|
182
|
+
@filenames = [Time.now.utc - 3700, Time.now.utc - 3610, Time.now.utc - 3590].map do |time|
|
183
|
+
"#{time.to_i}-1234-5678-9000/portrait.jpg"
|
184
|
+
end
|
185
|
+
@filenames << "not-a-cache/portrait.jpg"
|
186
|
+
@filenames.each { |filename| @grid[filename] = file }
|
187
|
+
end
|
188
|
+
|
189
|
+
it "cleans old cache files" do
|
190
|
+
@uploader_class.clean_cached_files!(3600)
|
191
|
+
expect(@grid.namespace.file_model.all.to_a.map(&:filename)).to eq @filenames[2..3]
|
192
|
+
end
|
193
|
+
end if CarrierWave::VERSION >= '2'
|
172
194
|
end
|
173
195
|
|
174
196
|
after do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '0.8'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '3'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '0.8'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: mongoid
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- gemfiles/carrierwave-1.1.gemfile
|
147
147
|
- gemfiles/carrierwave-1.2.gemfile
|
148
148
|
- gemfiles/carrierwave-1.3.gemfile
|
149
|
+
- gemfiles/carrierwave-2.0.gemfile
|
149
150
|
- gemfiles/mongoid-3.gemfile
|
150
151
|
- gemfiles/mongoid-4.gemfile
|
151
152
|
- gemfiles/mongoid-5.gemfile
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
- !ruby/object:Gem::Version
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
|
-
rubygems_version: 3.0.
|
188
|
+
rubygems_version: 3.0.3
|
188
189
|
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Mongoid support for CarrierWave
|