mongoid-grid_fs 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails"
4
+
5
+ gemspec
@@ -2,7 +2,7 @@
2
2
  #
3
3
  module Mongoid
4
4
  class GridFS
5
- const_set :Version, '1.7.1'
5
+ const_set :Version, '1.8.0'
6
6
 
7
7
  class << GridFS
8
8
  def version
@@ -211,6 +211,7 @@
211
211
  file
212
212
  rescue
213
213
  chunks.each{|chunk| chunk.destroy rescue nil}
214
+ raise
214
215
  end
215
216
 
216
217
  if defined?(Moped)
@@ -516,18 +517,50 @@
516
517
 
517
518
  def GridFS.extract_basename(object)
518
519
  filename = nil
520
+
519
521
  [:original_path, :original_filename, :path, :filename, :pathname].each do |msg|
520
522
  if object.respond_to?(msg)
521
523
  filename = object.send(msg)
522
524
  break
523
525
  end
524
526
  end
527
+
525
528
  filename ? cleanname(filename) : nil
526
529
  end
527
530
 
528
- def GridFS.extract_content_type(filename)
529
- content_type = MIME::Types.type_for(::File.basename(filename.to_s)).first
530
- content_type.to_s if content_type
531
+ MIME_TYPES = {
532
+ 'md' => 'text/x-markdown; charset=UTF-8'
533
+ }
534
+
535
+ def GridFS.mime_types
536
+ MIME_TYPES
537
+ end
538
+
539
+ def GridFS.extract_content_type(filename, options = {})
540
+ options.to_options!
541
+
542
+ basename = ::File.basename(filename.to_s)
543
+ parts = basename.split('.')
544
+ parts.shift
545
+ ext = parts.pop
546
+
547
+ default =
548
+ case
549
+ when options[:default]==false
550
+ nil
551
+ when options[:default]==true
552
+ "application/octet-stream"
553
+ else
554
+ (options[:default] || "application/octet-stream").to_s
555
+ end
556
+
557
+ content_type = mime_types[ext] || MIME::Types.type_for(::File.basename(filename.to_s)).first
558
+
559
+ if content_type
560
+ content_type.to_s
561
+ else
562
+ default
563
+ end
531
564
  end
532
565
 
533
566
  def GridFS.cleanname(pathname)
@@ -546,4 +579,19 @@
546
579
  class Mongoid::GridFS::Engine < Rails::Engine
547
580
  paths['app/models'] = File.dirname(__FILE__)
548
581
  end
582
+
583
+ module Mongoid::GridFSHelper
584
+ def grid_fs_render(grid_fs_file, options = {})
585
+ options.to_options!
586
+
587
+ if options[:inline] == false or options[:attachment] == true
588
+ headers['Content-Disposition'] = "attachment; filename=#{ grid_fs_file.filename }"
589
+ end
590
+
591
+ self.content_type = grid_fs_file.content_type
592
+ self.response_body = grid_fs_file
593
+ end
594
+ end
595
+
596
+ Mongoid::GridFS::Helper = Mongoid::GridFSHelper
549
597
  end
@@ -3,13 +3,14 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "mongoid-grid_fs"
6
- spec.version = "1.7.1"
6
+ spec.version = "1.8.0"
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
10
 
11
11
  spec.files =
12
- ["README.md",
12
+ ["Gemfile",
13
+ "README.md",
13
14
  "Rakefile",
14
15
  "lib",
15
16
  "lib/app",
@@ -35,6 +35,12 @@ Testing Mongoid::GridFs do
35
35
  assert{ g.filename == filename }
36
36
  end
37
37
 
38
+ test 'when error occurs (eg. missing file)' do
39
+ file = '/path/to/missing'
40
+
41
+ assert_raises(Errno::ENOENT){ GridFs.put(file) }
42
+ end
43
+
38
44
  end
39
45
 
40
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-grid_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -49,6 +49,7 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
+ - Gemfile
52
53
  - README.md
53
54
  - Rakefile
54
55
  - lib/app/models/mongoid/grid_fs.rb