mongoid-grid_fs 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -0
- data/lib/mongoid-grid_fs.rb +52 -4
- data/mongoid-grid_fs.gemspec +3 -2
- data/test/mongoid-grid_fs_test.rb +6 -0
- metadata +3 -2
data/Gemfile
ADDED
data/lib/mongoid-grid_fs.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
module Mongoid
|
4
4
|
class GridFS
|
5
|
-
const_set :Version, '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
|
-
|
529
|
-
|
530
|
-
|
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
|
data/mongoid-grid_fs.gemspec
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "mongoid-grid_fs"
|
6
|
-
spec.version = "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
|
-
["
|
12
|
+
["Gemfile",
|
13
|
+
"README.md",
|
13
14
|
"Rakefile",
|
14
15
|
"lib",
|
15
16
|
"lib/app",
|
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.
|
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-
|
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
|