From 29e7a0242853a5e102b6846b87723fc26a1ffb08 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 17 Jan 2009 11:12:18 -0600 Subject: Ensure any method sent to RewindableIO reads the original IO object [#1767 state:resolved] --- .../lib/action_controller/rewindable_input.rb | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'actionpack/lib/action_controller/rewindable_input.rb') diff --git a/actionpack/lib/action_controller/rewindable_input.rb b/actionpack/lib/action_controller/rewindable_input.rb index 058453ea68..36f655c51e 100644 --- a/actionpack/lib/action_controller/rewindable_input.rb +++ b/actionpack/lib/action_controller/rewindable_input.rb @@ -3,33 +3,17 @@ module ActionController class RewindableIO < ActiveSupport::BasicObject def initialize(io) @io = io - end - - def read(*args) - read_original_io - @io.read(*args) - end - - def rewind - read_original_io - @io.rewind - end - - def string - @string + @rewindable = io.is_a?(StringIO) end def method_missing(method, *args, &block) - @io.send(method, *args, &block) - end - - private - def read_original_io - unless @string - @string = @io.read - @io = StringIO.new(@string) - end + unless @rewindable + @io = StringIO.new(@io.read) + @rewindable = true end + + @io.__send__(method, *args, &block) + end end def initialize(app) -- cgit v1.2.3