mongoid_grid 0.0.7 → 0.0.8
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/lib/mongoid/grid.rb +26 -1
- metadata +3 -8
data/lib/mongoid/grid.rb
CHANGED
@@ -53,6 +53,17 @@ module Mongoid
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
##
|
57
|
+
# Create a method to set the attachment for binary string.
|
58
|
+
# eg: object.set_image(binary_string, "generated_filename.png")
|
59
|
+
define_method("set_#{name}") do |binary, filename|
|
60
|
+
if !binary.nil?
|
61
|
+
send(:create_attachment_raw, name, binary, filename)
|
62
|
+
else
|
63
|
+
send(:delete_attachment, name, send("#{name}_id"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
56
67
|
##
|
57
68
|
# Return the relative URL to the file for use with Rack::Grid
|
58
69
|
# eg: /grid/4ba69fde8c8f369a6e000003/somefile.png
|
@@ -115,11 +126,25 @@ module Mongoid
|
|
115
126
|
end
|
116
127
|
end
|
117
128
|
|
129
|
+
##
|
130
|
+
# Attachments we need to add after save.
|
131
|
+
# For binary String data.
|
132
|
+
def create_attachment_raw(name, binary, filename)
|
133
|
+
type = MIME::Types.type_for(filename).first
|
134
|
+
mime = type ? type.content_type : "application/octet-stream"
|
135
|
+
send("#{name}_id=", BSON::ObjectId.new)
|
136
|
+
send("#{name}_name=", filename)
|
137
|
+
send("#{name}_size=", binary.size)
|
138
|
+
send("#{name}_type=", mime)
|
139
|
+
create_attachment_queue[name] = binary
|
140
|
+
end
|
141
|
+
|
118
142
|
##
|
119
143
|
# Save an attachment to GridFS
|
120
144
|
def create_grid_attachment(name,file)
|
145
|
+
data = file.respond_to?(:read) ? file.read : file
|
121
146
|
grid.put(
|
122
|
-
|
147
|
+
data,
|
123
148
|
:filename => attributes["#{name}_name"],
|
124
149
|
:content_type => attributes["#{name}_type"],
|
125
150
|
:_id => attributes["#{name}_id"]
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Dusty Doris
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-16 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 62196421
|
44
41
|
segments:
|
45
42
|
- 2
|
46
43
|
- 0
|
@@ -78,7 +75,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
75
|
requirements:
|
79
76
|
- - ">="
|
80
77
|
- !ruby/object:Gem::Version
|
81
|
-
hash: 3
|
82
78
|
segments:
|
83
79
|
- 0
|
84
80
|
version: "0"
|
@@ -87,7 +83,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
83
|
requirements:
|
88
84
|
- - ">="
|
89
85
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
86
|
segments:
|
92
87
|
- 0
|
93
88
|
version: "0"
|