mongoid-grid_fs 2.4.0 → 2.5.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
- SHA1:
3
- metadata.gz: 2adba8b6e95828d619a449203b5d8d452110b353
4
- data.tar.gz: 3777d4236521b3c2b42d177551c8bb5915c79bff
2
+ SHA256:
3
+ metadata.gz: badeed24be962cfe0703db3b729a4d3941e4f707774be209b224b37f74fb709a
4
+ data.tar.gz: df22b750f61661cff90eaaceaf6faeb73ea75cbab44e2b52c4ae95bb22989f8d
5
5
  SHA512:
6
- metadata.gz: 70cd98b5cc29e726e957b5491e2464e69230b6086864191b2d3af114de4703efc0670fc32e8123e872d24f28825173828efbecbabe2a73d7d01a7ad7381becff
7
- data.tar.gz: 4654cf20cd201027cb99c771a325889d9603c3d5fe58f2fa55192a81670d87e6a814e68d28beff40d944c9cf67d154834bc7024f9fce927d1c782abc0582e1fb
6
+ metadata.gz: 59c26d3fbbd58640ca92808f1ee46f312092ed9139b551da5f99bf8418eac76815943a980e53e86347980a12e4089c7c8529eb3e548bf0bb0fe6b2753b4bf29f
7
+ data.tar.gz: 4ba07aa7b6319fcb8c62c0a50edec2e99321c0827220292b1dca1fd9f3710f1b37f5c9e3cbed1d9f15d77dc7a6a34058a4cb2b0d942e93895e5097a860a7bcf7
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  mongoid-grid_fs
2
2
  ---------------
3
3
 
4
- [![Gem Version](https://img.shields.io/gem/v/mongoid-grid_fs.svg)](https://rubygems.org/gems/mongoid-grid_fs)
5
- [![Build Status](https://travis-ci.org/mongoid/mongoid-grid_fs.svg)](https://travis-ci.org/mongoid/mongoid-grid_fs)
6
- [![Gem Downloads](https://img.shields.io/gem/dt/mongoid-grid_fs.svg)](https://rubygems.org/gems/mongoid-grid_fs)
4
+ [![Gem Version](https://badge.fury.io/rb/mongoid-grid_fs.svg)](https://badge.fury.io/rb/mongoid-grid_fs)
5
+ [![CI](https://github.com/mongoid/mongoid-grid_fs/actions/workflows/ci.yml/badge.svg)](https://github.com/mongoid/mongoid-grid_fs/actions/workflows/ci.yml)
7
6
 
8
7
  A pure Mongoid/Moped implementation of the MongoDB GridFS specification
9
8
 
data/Rakefile CHANGED
@@ -12,4 +12,4 @@ end
12
12
  require 'rubocop/rake_task'
13
13
  RuboCop::RakeTask.new(:rubocop)
14
14
 
15
- task default: [:rubocop, :test]
15
+ task default: %i[rubocop test]
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  class GridFs
3
- VERSION = '2.4.0'.freeze
3
+ VERSION = '2.5.0'.freeze
4
4
  end
5
5
  end
@@ -107,21 +107,13 @@ module Mongoid
107
107
 
108
108
  file.id = attributes.delete(:_id) if attributes.key?(:_id)
109
109
 
110
- if attributes.key?(:content_type)
111
- attributes[:contentType] = attributes.delete(:content_type)
112
- end
110
+ attributes[:contentType] = attributes.delete(:content_type) if attributes.key?(:content_type)
113
111
 
114
- if attributes.key?(:upload_date)
115
- attributes[:uploadDate] = attributes.delete(:upload_date)
116
- end
112
+ attributes[:uploadDate] = attributes.delete(:upload_date) if attributes.key?(:upload_date)
117
113
 
118
- if attributes.key?(:meta_data)
119
- attributes[:metadata] = attributes.delete(:meta_data)
120
- end
114
+ attributes[:metadata] = attributes.delete(:meta_data) if attributes.key?(:meta_data)
121
115
 
122
- if attributes.key?(:aliases)
123
- attributes[:aliases] = Array(attributes.delete(:aliases)).flatten.compact.map(&:to_s)
124
- end
116
+ attributes[:aliases] = Array(attributes.delete(:aliases)).flatten.compact.map(&:to_s) if attributes.key?(:aliases)
125
117
 
126
118
  md5 = Digest::MD5.new
127
119
  length = 0
@@ -142,7 +134,7 @@ module Mongoid
142
134
  GridFs.chunking(io, chunkSize) do |buf|
143
135
  md5 << buf
144
136
  length += buf.size
145
- chunk = file.chunks.create(data: binary_for(buf), n: n)
137
+ file.chunks.create(data: binary_for(buf), n: n)
146
138
  n += 1
147
139
  end
148
140
  end
@@ -154,7 +146,7 @@ module Mongoid
154
146
  file.update_attributes(attributes)
155
147
 
156
148
  file
157
- rescue
149
+ rescue StandardError
158
150
  file.destroy
159
151
  raise
160
152
  end
@@ -173,7 +165,7 @@ module Mongoid
173
165
 
174
166
  def delete(id)
175
167
  file_model.find(id).destroy
176
- rescue
168
+ rescue StandardError
177
169
  nil
178
170
  end
179
171
 
@@ -256,7 +248,7 @@ module Mongoid
256
248
 
257
249
  self.defaults = Defaults.new
258
250
 
259
- defaults.chunkSize = 4 * (mb = 2**20)
251
+ defaults.chunkSize = 4 * (2**20)
260
252
  defaults.contentType = 'application/octet-stream'
261
253
 
262
254
  field(:length, type: Integer, default: 0)
@@ -269,11 +261,11 @@ module Mongoid
269
261
  field(:aliases, type: Array)
270
262
  begin
271
263
  field(:metadata)
272
- rescue
264
+ rescue StandardError
273
265
  nil
274
266
  end
275
267
 
276
- required = %w(length chunkSize uploadDate md5)
268
+ required = %w[length chunkSize uploadDate md5]
277
269
 
278
270
  required.each do |f|
279
271
  validates_presence_of(f)
@@ -284,7 +276,7 @@ module Mongoid
284
276
  index(uploadDate: 1)
285
277
  index(md5: 1)
286
278
 
287
- has_many(:chunks, class_name: chunk_model_name, inverse_of: :files, dependent: :destroy, order: [:n, :asc])
279
+ has_many(:chunks, class_name: chunk_model_name, inverse_of: :files, dependent: :destroy, order: %i[n asc])
288
280
 
289
281
  def path
290
282
  filename
@@ -320,7 +312,7 @@ module Mongoid
320
312
 
321
313
  while fetched < chunks.size
322
314
  chunks.where(:n.lt => fetched + limit, :n.gte => fetched)
323
- .order_by([:n, :asc]).each do |chunk|
315
+ .order_by(%i[n asc]).each do |chunk|
324
316
  yield(chunk.to_s)
325
317
  end
326
318
 
@@ -456,7 +448,7 @@ module Mongoid
456
448
  end
457
449
 
458
450
  def self.chunking(io, chunk_size, &block)
459
- if io.method(:read).arity == 0
451
+ if io.method(:read).arity.zero?
460
452
  data = io.read
461
453
  i = 0
462
454
  loop do
@@ -481,7 +473,7 @@ module Mongoid
481
473
  pos = io.pos
482
474
  io.flush
483
475
  io.rewind
484
- rescue
476
+ rescue StandardError
485
477
  nil
486
478
  end
487
479
 
@@ -490,7 +482,7 @@ module Mongoid
490
482
  ensure
491
483
  begin
492
484
  io.pos = pos
493
- rescue
485
+ rescue StandardError
494
486
  nil
495
487
  end
496
488
  end
@@ -499,7 +491,7 @@ module Mongoid
499
491
  def self.extract_basename(object)
500
492
  filename = nil
501
493
 
502
- [:original_path, :original_filename, :path, :filename, :pathname].each do |msg|
494
+ %i[original_path original_filename path filename pathname].each do |msg|
503
495
  if object.respond_to?(msg)
504
496
  filename = object.send(msg)
505
497
  break
@@ -563,16 +555,14 @@ end
563
555
  #
564
556
  if defined?(Rails)
565
557
  class Mongoid::GridFs::Engine < Rails::Engine
566
- paths['app/models'] = File.dirname(File.expand_path('../', __FILE__))
558
+ paths['app/models'] = File.dirname(File.expand_path(__dir__))
567
559
  end
568
560
 
569
561
  module Mongoid::GridFsHelper
570
562
  def grid_fs_render(grid_fs_file, options = {})
571
563
  options.to_options!
572
564
 
573
- if (options[:inline] == false) || (options[:attachment] == true)
574
- headers['Content-Disposition'] = "attachment; filename=#{grid_fs_file.attachment_filename}"
575
- end
565
+ headers['Content-Disposition'] = "attachment; filename=#{grid_fs_file.attachment_filename}" if (options[:inline] == false) || (options[:attachment] == true)
576
566
 
577
567
  self.content_type = grid_fs_file.content_type
578
568
  self.response_body = grid_fs_file
data/test/helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  require 'rails'
4
2
  require 'stringio'
5
3
 
@@ -22,6 +20,4 @@ end
22
20
  Mongo::Logger.logger.level = Logger::INFO if defined?(Mongo) == 'constant'
23
21
 
24
22
  # Avoid annoying deprecation warning
25
- if I18n.respond_to?(:enforce_available_locales=)
26
- I18n.enforce_available_locales = false
27
- end
23
+ I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales=)
@@ -1,6 +1,6 @@
1
1
  require_relative 'helper'
2
2
 
3
- Testing Mongoid::GridFs do
3
+ _testing Mongoid::GridFs do
4
4
  ##
5
5
  #
6
6
  GridFs = Mongoid::GridFs
@@ -52,7 +52,7 @@ Testing Mongoid::GridFs do
52
52
  context '#get' do
53
53
  test 'default' do
54
54
  id = assert { GridFs::File.last.id }
55
- g = assert { GridFs.get(id) }
55
+ assert { GridFs.get(id) }
56
56
  end
57
57
  end
58
58
 
@@ -61,7 +61,7 @@ Testing Mongoid::GridFs do
61
61
  context '#delete' do
62
62
  test 'default' do
63
63
  id = assert { GridFs::File.last.id }
64
- g = assert { GridFs.get(id) }
64
+ assert { GridFs.get(id) }
65
65
  assert { GridFs.delete(id) }
66
66
  assert_raises(Mongoid::Errors::DocumentNotFound) { GridFs.get(id) }
67
67
  end
@@ -163,7 +163,7 @@ Testing Mongoid::GridFs do
163
163
  test 'having file size more than 42mb' do
164
164
  require 'tempfile'
165
165
 
166
- orig, copy = %w(orig copy).map do |suffix|
166
+ orig, copy = %w[orig copy].map do |suffix|
167
167
  Tempfile.new("mongoid-grid_fs~43mb.#{suffix}")
168
168
  end
169
169
 
@@ -202,7 +202,7 @@ Testing Mongoid::GridFs do
202
202
 
203
203
  count = GridFs::File.count
204
204
 
205
- assert { ns.file_model.count == 0 }
205
+ assert { ns.file_model.count.zero? }
206
206
  assert { ns.put __FILE__ }
207
207
  assert { ns.file_model.count == 1 }
208
208
 
data/test/testing.rb CHANGED
@@ -1,7 +1,7 @@
1
- # -*- encoding : utf-8 -*-
1
+
2
2
  require 'minitest/autorun'
3
3
 
4
- testdir = File.expand_path(File.dirname(__FILE__))
4
+ testdir = __dir__
5
5
  rootdir = File.dirname(testdir)
6
6
  libdir = File.join(rootdir, 'lib')
7
7
 
@@ -16,7 +16,7 @@ class Testing
16
16
  def self.for(*args)
17
17
  string = args.flatten.compact.join('-')
18
18
  words = string.to_s.scan(/\w+/)
19
- words.map! { |word| word.gsub /[^0-9a-zA-Z_-]/, '' }
19
+ words.map! { |word| word.gsub(/[^0-9a-zA-Z_-]/, '') }
20
20
  words.delete_if { |word| word.nil? || word.strip.empty? }
21
21
  new(words.join('-').downcase)
22
22
  end
@@ -35,7 +35,7 @@ class Testing
35
35
  end
36
36
  end
37
37
 
38
- def Testing(*args, &block)
38
+ def _testing(*args, &block)
39
39
  Class.new(::Minitest::Test) do
40
40
  i_suck_and_my_tests_are_order_dependent!
41
41
 
@@ -62,7 +62,7 @@ def Testing(*args, &block)
62
62
  def slug_for(*args)
63
63
  string = [context, args].flatten.compact.join('-')
64
64
  words = string.to_s.scan(/\w+/)
65
- words.map! { |word| word.gsub /[^0-9a-zA-Z_-]/, '' }
65
+ words.map! { |word| word.gsub(/[^0-9a-zA-Z_-]/, '') }
66
66
  words.delete_if { |word| word.nil? || word.strip.empty? }
67
67
  words.join('-').downcase.sub(/_$/, '')
68
68
  end
@@ -72,7 +72,7 @@ def Testing(*args, &block)
72
72
  end
73
73
 
74
74
  def testno
75
- '%05d' % (@testno ||= 0)
75
+ format('%05d', (@testno ||= 0))
76
76
  ensure
77
77
  @testno += 1
78
78
  end
@@ -111,7 +111,7 @@ def Testing(*args, &block)
111
111
  #
112
112
  const_set(:Testno, '0')
113
113
  slug = slug_for(*args).tr('-', '_')
114
- name = ['TESTING', '%03d' % const_get(:Testno), slug].delete_if(&:empty?).join('_')
114
+ name = ['TESTING', format('%03d', const_get(:Testno)), slug].delete_if(&:empty?).join('_')
115
115
  name = name.upcase!
116
116
  const_set(:Name, name)
117
117
  const_set(:Missing, Object.new.freeze)
@@ -125,9 +125,7 @@ def Testing(*args, &block)
125
125
  options = args.first
126
126
  expected = getopt(:expected, options) { missing }
127
127
  actual = getopt(:actual, options) { missing }
128
- if (expected == missing) && (actual == missing)
129
- actual, expected, *ignored = options.to_a.flatten
130
- end
128
+ actual, expected, = options.to_a.flatten if (expected == missing) && (actual == missing)
131
129
  expected = expected.call if expected.respond_to?(:call)
132
130
  actual = actual.call if actual.respond_to?(:call)
133
131
  assert_equal(expected, actual)
@@ -135,16 +133,14 @@ def Testing(*args, &block)
135
133
 
136
134
  result = if block
137
135
  label = "assert(#{args.join(' ')})"
138
- result = nil
139
- result = yield
140
- __assert__(result, label)
141
- result
136
+ yield
142
137
  else
143
138
  result = args.shift
144
139
  label = "assert(#{args.join(' ')})"
145
- __assert__(result, label)
146
140
  result
147
- end
141
+ end
142
+ __assert__(result, label)
143
+ result
148
144
  end
149
145
 
150
146
  def missing
@@ -191,7 +187,7 @@ end
191
187
 
192
188
  if $PROGRAM_NAME == __FILE__
193
189
 
194
- Testing 'Testing' do
190
+ _testing 'Testing' do
195
191
  testing('foo') { assert true }
196
192
  test { assert true }
197
193
  p instance_methods.grep(/test/)
metadata CHANGED
@@ -1,35 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-grid_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mongoid
14
+ name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
20
- - - "<"
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
21
25
  - !ruby/object:Gem::Version
22
- version: '8.0'
23
- type: :runtime
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid-danger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
26
44
  requirements:
27
45
  - - ">="
28
46
  - !ruby/object:Gem::Version
29
- version: '3.0'
30
- - - "<"
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
31
53
  - !ruby/object:Gem::Version
32
- version: '8.0'
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.36.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.36.0
33
83
  - !ruby/object:Gem::Dependency
34
84
  name: mime-types
35
85
  requirement: !ruby/object:Gem::Requirement
@@ -51,25 +101,25 @@ dependencies:
51
101
  - !ruby/object:Gem::Version
52
102
  version: '4.0'
53
103
  - !ruby/object:Gem::Dependency
54
- name: minitest
104
+ name: mongoid
55
105
  requirement: !ruby/object:Gem::Requirement
56
106
  requirements:
57
107
  - - ">="
58
108
  - !ruby/object:Gem::Version
59
- version: 5.7.0
109
+ version: '3.0'
60
110
  - - "<"
61
111
  - !ruby/object:Gem::Version
62
- version: '6.0'
63
- type: :development
112
+ version: '9.0'
113
+ type: :runtime
64
114
  prerelease: false
65
115
  version_requirements: !ruby/object:Gem::Requirement
66
116
  requirements:
67
117
  - - ">="
68
118
  - !ruby/object:Gem::Version
69
- version: 5.7.0
119
+ version: '3.0'
70
120
  - - "<"
71
121
  - !ruby/object:Gem::Version
72
- version: '6.0'
122
+ version: '9.0'
73
123
  description: A pure Mongoid/Moped implementation of the MongoDB GridFS specification
74
124
  email:
75
125
  - ara.t.howard@gmail.com
@@ -93,7 +143,7 @@ homepage: https://github.com/mongoid/mongoid-grid_fs
93
143
  licenses:
94
144
  - Ruby
95
145
  metadata: {}
96
- post_install_message:
146
+ post_install_message:
97
147
  rdoc_options: []
98
148
  require_paths:
99
149
  - lib
@@ -108,9 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
158
  - !ruby/object:Gem::Version
109
159
  version: '0'
110
160
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.6.12
113
- signing_key:
161
+ rubygems_version: 3.3.17
162
+ signing_key:
114
163
  specification_version: 4
115
164
  summary: A MongoDB GridFS implementation for Mongoid
116
165
  test_files: