Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from sirlantis/patch-10

Leave reading the IO to Mongo::Grid
  • Loading branch information...
commit b8b1175a08afc32739860ae610a59a1d549d5e4e 2 parents f7a0609 + 9f08fcc
@bkeepers bkeepers authored
View
2  lib/joint/instance_methods.rb
@@ -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
13 lib/joint/io.rb
@@ -1,3 +1,5 @@
+require 'stringio'
+
module Joint
class IO
attr_accessor :name, :content, :type, :size
@@ -5,10 +7,17 @@ class IO
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
4 test/helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.