Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #11 from sirlantis/patch-10

Leave reading the IO to Mongo::Grid
  • Loading branch information...
commit b8b1175a08afc32739860ae610a59a1d549d5e4e 2 parents f7a0609 + 9f08fcc
Brandon Keepers bkeepers authored
2  lib/joint/instance_methods.rb
@@ -19,7 +19,7 @@ def save_attachments
19 19 next unless io.respond_to?(:read)
20 20 io.rewind if io.respond_to?(:rewind)
21 21 grid.delete(send(name).id)
22   - grid.put(io.read, {
  22 + grid.put(io, {
23 23 :_id => send(name).id,
24 24 :filename => send(name).name,
25 25 :content_type => send(name).type,
13 lib/joint/io.rb
... ... @@ -1,3 +1,5 @@
  1 +require 'stringio'
  2 +
1 3 module Joint
2 4 class IO
3 5 attr_accessor :name, :content, :type, :size
@@ -5,10 +7,17 @@ class IO
5 7 def initialize(attrs={})
6 8 attrs.each { |key, value| send("#{key}=", value) }
7 9 @type ||= 'plain/text'
8   - @size ||= @content.size unless @content.nil?
  10 + end
  11 +
  12 + def content=(value)
  13 + @io = StringIO.new(value || nil)
  14 + @size = value ? value.size : 0
  15 + end
  16 +
  17 + def read(*args)
  18 + @io.read(*args)
9 19 end
10 20
11 21 alias path name
12   - alias read content
13 22 end
14 23 end
4 test/helper.rb
@@ -70,7 +70,9 @@ def rewind_files
70 70 end
71 71
72 72 def open_file(name)
73   - File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
  73 + f = File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
  74 + f.binmode
  75 + f
74 76 end
75 77
76 78 def grid

0 comments on commit b8b1175

Please sign in to comment.
Something went wrong with that request. Please try again.