Class: Merb::Rack::StreamWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/rack/stream_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ StreamWrapper

:api: private



6
7
8
# File 'lib/merb-core/rack/stream_wrapper.rb', line 6

def initialize(body)
   @body = body
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object

:api: private



43
44
45
# File 'lib/merb-core/rack/stream_wrapper.rb', line 43

def method_missing(sym, *args, &blk)
  @body.send(sym, *args, &blk)
end

Instance Method Details

#==(other) ⇒ Object

:api: private



38
39
40
# File 'lib/merb-core/rack/stream_wrapper.rb', line 38

def ==(other)
  @body == other
end

#each(&callback) ⇒ Object

:api: private



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/merb-core/rack/stream_wrapper.rb', line 11

def each(&callback)
  if Proc === @body
    @writer = lambda { |x| callback.call(x) }
    @body.call(self)
  elsif @body.is_a?(String)
    @body.each_line(&callback)
  elsif @body.nil?
    @body.to_s.each_line(&callback)
  elsif @body.is_a?(Integer)
    @body.to_s.each_line(&callback)
  else
    @body.each(&callback)
  end
end

#to_sObject

:api: private



33
34
35
# File 'lib/merb-core/rack/stream_wrapper.rb', line 33

def to_s
  @body.to_s
end

#write(str) ⇒ Object

:api: private



27
28
29
30
# File 'lib/merb-core/rack/stream_wrapper.rb', line 27

def write(str)
  @writer.call str.to_s
  str
end