mongoid-grid_fs 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDA4MTUxMWE3YTM1ODFjM2M1NzAxOTM1MmJkMmE5ZGNhYzc4ZjdlMw==
4
+ MzQ5NjI1MDZlZmExMmYyNGRjNjRkMTlhZDk5ZDg3YzBjYzI0MmYzOA==
5
5
  data.tar.gz: !binary |-
6
- NWEwZWE1ODhmMzk0MGNkOWViMDdjZjI4ZTNjYTZjMDczZGIzODAzNA==
6
+ NWY5ZWNmNTgzZjg4YzFmM2UwYjg5MjkyZTY0ZTYyZWY3MjFiZTJkYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGNjNzEzYmE1ODU0YWUxNWQ2MGRiOWQ5Nzc5YWYxNDNjNDJmODJkYWEyOGEw
10
- YmQ1YTc4ZmRhZTc4MDY2ODA4NGZjNzM3Zjk1MzY1NzBkOTI0NWU2YTg4Nzc5
11
- Y2FjMmUyNDk0NDNjYWZjZDUxODBmYmRkZjYwMTUxMmVkYzZhYWI=
9
+ ZTlhNDFiNGQxNTllYTIyZTVhM2U2NjdkNzc0NzA0ODk1ZDE3ODk1MzNkMWJm
10
+ YTQ1YzNkZThjYjg5OGQ0ZDVmYzY4NGEwY2M2NzY5NTMyY2NjMDI3OWMzNDFi
11
+ ZjI3ZmI3NTY5YWNiNmIxNmFkYjdmZTgwNGNhNzU5OTIzNTZiNzU=
12
12
  data.tar.gz: !binary |-
13
- NGIzMjdmZDE5ZmYzYmFiY2QzNjI4MTQ3NjVkMzY3MGY3OWUwMDJjNzhmOTAy
14
- NjVmNjczMWEzYjczMDcwMTcyM2NkNGE4MDMzNjhmY2JhOTc2YTczY2EwNmNh
15
- NDJmMGYzMzdmMTRlZTczNjEzZmJjNzY5ZTFlMTE3MGUyN2ZjMjE=
13
+ MDczNzdlNDY5NDZkMDI3M2UwMDdmNjI2NzhlYjlmMDA0Y2IwNWRiNzY1YWU4
14
+ N2QwMjM5YWY3ZDk3NWM5YjVkN2NkYjEzYmU2MmU3MzJjN2U5MzZlNjU5YjU2
15
+ Zjc1ZGQyZTcxMmU4ZjczNTFkZDhmMTNkMWQzYzFlMjU1MTk4NTQ=
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ same as Ruby's
2
+
3
+ http://www.ruby-lang.org/en/about/license.txt
data/README.md CHANGED
@@ -10,20 +10,12 @@ SYNOPSIS
10
10
  --------
11
11
 
12
12
  ````ruby
13
-
14
- require 'mongoid-grid_fs'
15
-
16
- grid_fs = Mongoid::GridFs
17
-
18
- g = grid_fs.put(readable)
19
-
20
- g = g.id
21
-
22
- grid_fs.get(id)
23
-
24
- grid_fs.delete(id)
25
-
26
-
13
+ require 'mongoid-grid_fs'
14
+ grid_fs = Mongoid::GridFs
15
+ g = grid_fs.put(readable)
16
+ id = g.id
17
+ grid_fs.get(id)
18
+ grid_fs.delete(id)
27
19
  ````
28
20
 
29
21
  DESCRIPTION
data/Rakefile CHANGED
@@ -68,10 +68,10 @@ end
68
68
 
69
69
  task :gemspec do
70
70
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
71
- ignore_directories = ['pkg', 'db']
72
- ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db'
71
+ ignore_directories = ['pkg', 'db', 'vendor', 'gemfiles']
72
+ ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['Gemfile*'] + %w'db'
73
73
 
74
- shiteless =
74
+ shiteless =
75
75
  lambda do |list|
76
76
  list.delete_if do |entry|
77
77
  next unless test(?e, entry)
@@ -79,9 +79,8 @@ task :gemspec do
79
79
  ignore_extensions.any?{|ext| ext === extension}
80
80
  end
81
81
  list.delete_if do |entry|
82
- next unless test(?d, entry)
83
82
  dirname = File.expand_path(entry)
84
- ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
83
+ ignore_directories.any?{|dir| dirname.include?(File.expand_path(dir)) }
85
84
  end
86
85
  list.delete_if do |entry|
87
86
  next unless test(?f, entry)
@@ -99,6 +98,7 @@ task :gemspec do
99
98
  test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
100
99
  summary = This.summary || This.synopsis || "#{ lib } kicks the ass"
101
100
  description = This.description || summary
101
+ license = 'Ruby'
102
102
 
103
103
  if This.extensions.nil?
104
104
  This.extensions = []
@@ -136,6 +136,7 @@ task :gemspec do
136
136
  spec.platform = Gem::Platform::RUBY
137
137
  spec.summary = <%= lib.inspect %>
138
138
  spec.description = <%= description.inspect %>
139
+ spec.license = <%= license.inspect %>
139
140
 
140
141
  spec.files =\n<%= files.sort.pretty_inspect %>
141
142
  spec.executables = <%= executables.inspect %>
@@ -2,7 +2,7 @@
2
2
  #
3
3
  module Mongoid
4
4
  class GridFS
5
- const_set :Version, '1.9.0'
5
+ const_set :Version, '1.9.1'
6
6
 
7
7
  class << GridFS
8
8
  def version
@@ -11,8 +11,8 @@
11
11
 
12
12
  def dependencies
13
13
  {
14
- 'mongoid' => [ 'mongoid' , '~> 3.0' ] ,
15
- 'mime/types' => [ 'mime-types' , '~> 1.19'] ,
14
+ 'mongoid' => [ 'mongoid' , '>= 3.0', '< 5.0' ] ,
15
+ 'mime/types' => [ 'mime-types' , '>= 1.19', '< 2.0'] ,
16
16
  }
17
17
  end
18
18
 
@@ -82,7 +82,7 @@
82
82
  []=
83
83
  clear
84
84
  )
85
-
85
+
86
86
  to_delegate.each do |method|
87
87
  class_eval <<-__
88
88
  def self.#{ method }(*args, &block)
@@ -214,13 +214,11 @@
214
214
  raise
215
215
  end
216
216
 
217
- if defined?(Moped)
218
- def binary_for(*buf)
217
+ def binary_for(*buf)
218
+ if defined?(Moped::BSON)
219
219
  Moped::BSON::Binary.new(:generic, buf.join)
220
- end
221
- else
222
- def binary_for(buf)
223
- BSON::Binary.new(buf.bytes.to_a)
220
+ else
221
+ BSON::Binary.new(buf.join, :generic)
224
222
  end
225
223
  end
226
224
 
@@ -296,6 +294,7 @@
296
294
 
297
295
  Class.new do
298
296
  include Mongoid::Document
297
+ include Mongoid::Attributes::Dynamic if Mongoid::VERSION.to_i >= 4
299
298
 
300
299
  singleton_class = class << self; self; end
301
300
 
@@ -306,7 +305,8 @@
306
305
  attr_accessor :defaults
307
306
  end
308
307
 
309
- self.default_collection_name = "#{ prefix }.files"
308
+ self.store_in :collection => "#{ prefix }.files"
309
+
310
310
  self.defaults = Defaults.new
311
311
 
312
312
  self.defaults.chunkSize = 4 * (mb = 2**20)
@@ -317,7 +317,7 @@
317
317
 
318
318
  field(:length, :type => Integer, :default => 0)
319
319
  field(:chunkSize, :type => Integer, :default => defaults.chunkSize)
320
- field(:uploadDate, :type => Date, :default => Time.now.utc)
320
+ field(:uploadDate, :type => Time, :default => Time.now.utc)
321
321
  field(:md5, :type => String, :default => Digest::MD5.hexdigest(''))
322
322
 
323
323
  %w( filename contentType length chunkSize uploadDate md5 ).each do |f|
@@ -327,7 +327,7 @@
327
327
 
328
328
  has_many(:chunks, :class_name => chunk_model_name, :inverse_of => :files, :dependent => :destroy, :order => [:n, :asc])
329
329
 
330
- index({:filename => 1}, :unique => true)
330
+ index({:filename => 1}, :unique => true)
331
331
 
332
332
  def path
333
333
  filename
@@ -342,8 +342,15 @@
342
342
  end
343
343
 
344
344
  def each(&block)
345
- chunks.all.order_by([:n, :asc]).each do |chunk|
346
- block.call(chunk.to_s)
345
+ fetched, limit = 0, 7
346
+
347
+ while fetched < chunks.size
348
+ chunks.where(:n.lt => fetched+limit, :n.gte => fetched).
349
+ order_by([:n, :asc]).each do |chunk|
350
+ block.call(chunk.to_s)
351
+ end
352
+
353
+ fetched += limit
347
354
  end
348
355
  end
349
356
 
@@ -352,7 +359,7 @@
352
359
  when Range
353
360
  range = args.first
354
361
  first_chunk = (range.min / chunkSize).floor
355
- last_chunk = (range.max / chunkSize).ceil
362
+ last_chunk = (range.max / chunkSize).floor
356
363
  offset = range.min % chunkSize
357
364
  length = range.max - range.min + 1
358
365
  when Fixnum
@@ -360,7 +367,7 @@
360
367
  start = self.length + start if start < 0
361
368
  length = args.size == 2 ? args.last : 1
362
369
  first_chunk = (start / chunkSize).floor
363
- last_chunk = ((start + length) / chunkSize).ceil
370
+ last_chunk = ((start + length) / chunkSize).floor
364
371
  offset = start % chunkSize
365
372
  end
366
373
 
@@ -407,7 +414,7 @@
407
414
  contentType
408
415
  end
409
416
 
410
- def update_date
417
+ def update_date
411
418
  updateDate
412
419
  end
413
420
 
@@ -439,14 +446,14 @@
439
446
  attr_accessor :namespace
440
447
  end
441
448
 
442
- self.default_collection_name = "#{ prefix }.chunks"
449
+ self.store_in :collection => "#{ prefix }.chunks"
443
450
 
444
451
  field(:n, :type => Integer, :default => 0)
445
- field(:data, :type => (defined?(Moped) ? Moped::BSON::Binary : BSON::Binary))
452
+ field(:data, :type => (defined?(Moped::BSON) ? Moped::BSON::Binary : BSON::Binary))
446
453
 
447
454
  belongs_to(:file, :foreign_key => :files_id, :class_name => file_model_name)
448
455
 
449
- index({:files_id => 1, :n => -1}, :unique => true)
456
+ index({:files_id => 1, :n => -1}, :unique => true)
450
457
 
451
458
  def namespace
452
459
  self.class.namespace
@@ -3,13 +3,14 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "mongoid-grid_fs"
6
- spec.version = "1.9.0"
6
+ spec.version = "1.9.1"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "mongoid-grid_fs"
9
9
  spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
10
+ spec.license = "Ruby"
10
11
 
11
12
  spec.files =
12
- ["Gemfile",
13
+ ["LICENSE",
13
14
  "README.md",
14
15
  "Rakefile",
15
16
  "lib",
@@ -35,9 +36,9 @@ Gem::Specification::new do |spec|
35
36
  spec.test_files = nil
36
37
 
37
38
 
38
- spec.add_dependency(*["mongoid", "~> 3.0"])
39
+ spec.add_dependency(*["mongoid", ">= 3.0", "< 5.0"])
39
40
 
40
- spec.add_dependency(*["mime-types", "~> 1.19"])
41
+ spec.add_dependency(*["mime-types", ">= 1.19", "< 2.0"])
41
42
 
42
43
 
43
44
  spec.extensions.push(*[])
data/test/helper.rb CHANGED
@@ -21,4 +21,9 @@ Mongoid.configure do |config|
21
21
  config.connect_to('mongoid-grid_fs_test')
22
22
  end
23
23
 
24
+ BEGIN {
25
+ gem 'rails', '>= 3', '< 4'
26
+ require 'rails'
27
+ require 'active_model'
28
+ }
24
29
 
@@ -8,8 +8,8 @@ Testing Mongoid::GridFs do
8
8
  Mongoid::GridFS
9
9
 
10
10
  prepare do
11
- GridFS::File.destroy_all
12
- GridFS::Chunk.destroy_all
11
+ GridFS::File.delete_all
12
+ GridFS::Chunk.delete_all
13
13
  end
14
14
 
15
15
  ##
@@ -35,6 +35,14 @@ Testing Mongoid::GridFs do
35
35
  assert{ g.filename == filename }
36
36
  end
37
37
 
38
+ test 'with your own attributes' do
39
+ my_value = "my_value"
40
+
41
+ g = assert{ GridFS.put(__FILE__, :my_value => my_value) }
42
+
43
+ assert{ g.my_value == my_value }
44
+ end
45
+
38
46
  test 'when error occurs (eg. missing file)' do
39
47
  file = '/path/to/missing'
40
48
 
@@ -76,7 +84,7 @@ Testing Mongoid::GridFs do
76
84
  path = 'a.rb'
77
85
  data = IO.read(__FILE__)
78
86
 
79
- sio = SIO.new(path, data)
87
+ sio = SIO.new(path, data)
80
88
 
81
89
  g = assert{ GridFs[path] = sio and GridFs[path] }
82
90
 
@@ -160,13 +168,33 @@ Testing Mongoid::GridFs do
160
168
  end
161
169
  end
162
170
 
171
+ ##
172
+ #
173
+ context 'iterating each chunk' do
174
+ test 'having file size more than 42mb' do
175
+ require 'tempfile'
176
+
177
+ orig, copy = %w{orig copy}.map do |suffix|
178
+ Tempfile.new("mongoid-grid_fs~43mb.#{suffix}")
179
+ end
180
+
181
+ assert system("dd if=/dev/zero of=#{orig.path} bs=#{43*1024*1024} count=1 &> /dev/null")
182
+
183
+ GridFs.get(GridFs.put(orig.path).id).each do |chunk|
184
+ copy.print(chunk.to_s)
185
+ end
186
+
187
+ assert { File.size(copy.path) == File.size(orig.path) }
188
+ end
189
+ end
190
+
163
191
  ##
164
192
  #
165
193
  context 'namespaces' do
166
194
  test 'default' do
167
195
  assert{ GridFs.namespace.prefix == 'fs' }
168
- assert{ GridFs.file_model.collection_name == 'fs.files' }
169
- assert{ GridFs.chunk_model.collection_name == 'fs.chunks' }
196
+ assert{ GridFs.file_model.collection_name.to_s == 'fs.files' }
197
+ assert{ GridFs.chunk_model.collection_name.to_s == 'fs.chunks' }
170
198
  end
171
199
 
172
200
  test 'new' do
@@ -175,10 +203,10 @@ Testing Mongoid::GridFs do
175
203
  assert{ ns.prefix == 'ns' }
176
204
 
177
205
  assert{ ns.file_model < Mongoid::Document }
178
- assert{ ns.file_model.collection_name == 'ns.files' }
206
+ assert{ ns.file_model.collection_name.to_s == 'ns.files' }
179
207
 
180
208
  assert{ ns.chunk_model < Mongoid::Document }
181
- assert{ ns.chunk_model.collection_name == 'ns.chunks' }
209
+ assert{ ns.chunk_model.collection_name.to_s == 'ns.chunks' }
182
210
 
183
211
  assert{ ns.file_model.destroy_all }
184
212
 
@@ -204,7 +232,7 @@ Testing Mongoid::GridFs do
204
232
 
205
233
  expanded = proc{|paths| Array(paths).map{|path| File.expand_path(path)}}
206
234
 
207
- assert{
235
+ assert{
208
236
  expanded[ Mongoid::GridFS::Engine.paths['app/models'] ] == expanded[ libdir ]
209
237
  }
210
238
  end
@@ -212,7 +240,7 @@ Testing Mongoid::GridFs do
212
240
 
213
241
  protected
214
242
  def object_id_re
215
- object_id = defined?(Moped) ? Moped::BSON::ObjectId.new : BSON::ObjectId.new
243
+ object_id = defined?(Moped::BSON) ? Moped::BSON::ObjectId.new : BSON::ObjectId.new
216
244
 
217
245
  %r| \w{#{ object_id.to_s.size }} |iomx
218
246
  end
metadata CHANGED
@@ -1,50 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-grid_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: mime-types
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ~>
37
+ - - ! '>='
32
38
  - !ruby/object:Gem::Version
33
39
  version: '1.19'
40
+ - - <
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ~>
47
+ - - ! '>='
39
48
  - !ruby/object:Gem::Version
40
49
  version: '1.19'
50
+ - - <
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
41
53
  description: a mongoid 3/moped compatible implementation of the grid_fs specification
42
54
  email: ara.t.howard@gmail.com
43
55
  executables: []
44
56
  extensions: []
45
57
  extra_rdoc_files: []
46
58
  files:
47
- - Gemfile
59
+ - LICENSE
48
60
  - README.md
49
61
  - Rakefile
50
62
  - lib/app/models/mongoid/grid_fs.rb
@@ -56,7 +68,8 @@ files:
56
68
  - test/mongoid-grid_fs_test.rb
57
69
  - test/testing.rb
58
70
  homepage: https://github.com/ahoward/mongoid-grid_fs
59
- licenses: []
71
+ licenses:
72
+ - Ruby
60
73
  metadata: {}
61
74
  post_install_message:
62
75
  rdoc_options: []
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "rails"
4
-
5
- gemspec