Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

leave reading the IO to Mongo::Grid

  • Loading branch information...
commit 9f08fcc976c3a80310ea7d66499c9e58332afeab 1 parent e302b86
@sirlantis sirlantis authored
Showing with 12 additions and 3 deletions.
  1. +1 −1  lib/joint/instance_methods.rb
  2. +11 −2 lib/joint/io.rb
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
Please sign in to comment.
Something went wrong with that request. Please try again.