Leave reading the IO to Mongo::Grid #11

Merged
merged 2 commits into from Jul 29, 2011
@@ -19,7 +19,7 @@ def save_attachments
next unless io.respond_to?(:read)
io.rewind if io.respond_to?(:rewind)
grid.delete(send(name).id)
- grid.put(io.read, {
+ grid.put(io, {
:_id => send(name).id,
:filename => send(name).name,
:content_type => send(name).type,
View
@@ -1,14 +1,23 @@
+require 'stringio'
+
module Joint
class IO
attr_accessor :name, :content, :type, :size
def initialize(attrs={})
attrs.each { |key, value| send("#{key}=", value) }
@type ||= 'plain/text'
- @size ||= @content.size unless @content.nil?
+ end
+
+ def content=(value)
+ @io = StringIO.new(value || nil)
+ @size = value ? value.size : 0
+ end
+
+ def read(*args)
+ @io.read(*args)
end
alias path name
- alias read content
end
end
View
@@ -70,7 +70,9 @@ def rewind_files
end
def open_file(name)
- File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
+ f = File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
+ f.binmode
+ f
end
def grid