Class: Rack::MiniProfiler::BodyAddProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_profiler/body_add_proxy.rb

Overview

This class acts as a proxy to the Body so that we can safely append to the end without knowing about the internals of the body class.

Instance Method Summary collapse

Constructor Details

#initialize(body, additional_text) ⇒ BodyAddProxy

Returns a new instance of BodyAddProxy.



8
9
10
11
# File 'lib/mini_profiler/body_add_proxy.rb', line 8

def initialize(body, additional_text)
  @body = body
  @additional_text = additional_text
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



17
18
19
# File 'lib/mini_profiler/body_add_proxy.rb', line 17

def method_missing(*args, &block)
  @body.__send__(*args, &block)
end

Instance Method Details

#each {|@additional_text| ... } ⇒ Object

Yields:

  • (@additional_text)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mini_profiler/body_add_proxy.rb', line 29

def each(&block)

  # In ruby 1.9 we don't support String#each
  if @body.is_a?(String)
    yield @body
  else
    @body.each(&block)
  end

  yield @additional_text
  self
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mini_profiler/body_add_proxy.rb', line 13

def respond_to?(*args)
  super or @body.respond_to?(*args)
end

#to_strObject

In the case of to_str we don’t want to use method_missing as it might avoid a call to each (such as in Rack::Test)



23
24
25
26
27
# File 'lib/mini_profiler/body_add_proxy.rb', line 23

def to_str
  result = ""
  each {|token| result << token}
  result
end