matic_grid 0.0.2 → 0.0.3
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/matic_grid.rb +12 -13
- metadata +4 -4
data/lib/matic_grid.rb
CHANGED
@@ -44,13 +44,13 @@ module Mongomatic
|
|
44
44
|
# Create a method to set the attachment
|
45
45
|
# eg: object.image = File.open('/tmp/somefile.jpg')
|
46
46
|
define_method("#{name}=") do |file|
|
47
|
+
# delete the old file if it exists
|
48
|
+
send(:delete_attachment, name, self["#{name}_id"]) unless self["#{name}_id"].blank?
|
47
49
|
case
|
48
50
|
when file.is_a?(Hash) && file[:tempfile]
|
49
51
|
send(:create_attachment, name, file)
|
50
52
|
when file.respond_to?(:read)
|
51
53
|
send(:create_attachment, name, file)
|
52
|
-
else
|
53
|
-
send(:delete_attachment, name, self["#{name}_id"])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -150,13 +150,14 @@ module Mongomatic
|
|
150
150
|
mime = type ? type.content_type : "application/octet-stream"
|
151
151
|
end
|
152
152
|
when file.respond_to?(:read)
|
153
|
-
filename =
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
153
|
+
filename = case
|
154
|
+
when file.respond_to?(:original_filename) && file.original_filename
|
155
|
+
file.original_filename
|
156
|
+
when file.respond_to?(:tempfile)
|
157
|
+
File.basename(file.tempfile.path)
|
158
|
+
else
|
159
|
+
File.basename(file.path)
|
160
|
+
end
|
160
161
|
size = File.size(file.respond_to?(:tempfile) ? file.tempfile : file)
|
161
162
|
type = MIME::Types.type_for(filename).first
|
162
163
|
mime = type ? type.content_type : "application/octet-stream"
|
@@ -189,10 +190,8 @@ module Mongomatic
|
|
189
190
|
data = case
|
190
191
|
when file.is_a?(Hash)
|
191
192
|
file[:tempfile].read
|
192
|
-
when file.respond_to?(:read)
|
193
|
-
file.read
|
194
193
|
else
|
195
|
-
file
|
194
|
+
file.respond_to?(:read) ? file.read : file
|
196
195
|
end
|
197
196
|
grid.put(
|
198
197
|
data,
|
@@ -244,4 +243,4 @@ module Mongomatic
|
|
244
243
|
end
|
245
244
|
end
|
246
245
|
end
|
247
|
-
end
|
246
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matic_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160795660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160795660
|
25
25
|
description: Plugin for Mongomatic to attach files via Grid
|
26
26
|
email: github@dusty.name
|
27
27
|
executables: []
|