Class: Cheat::Controllers::Responder::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/cheat/responder.rb

Constant Summary collapse

TYPES =
{
  :yaml => %w[application/yaml text/yaml],
  :text => %w[text/plain],
  :html => %w[text/html */* application/html],
  :xml  => %w[application/xml]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accept) ⇒ Response

Returns a new instance of Response.



25
# File 'lib/cheat/responder.rb', line 25

def initialize(accept) @accept = accept end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



34
35
36
37
38
39
# File 'lib/cheat/responder.rb', line 34

def method_missing(method, *args)
  if TYPES[method] && @accept =~ Regexp.union(*TYPES[method])
    @content_type = TYPES[method].first
    @body = yield if block_given?
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/cheat/responder.rb', line 24

def body
  @body
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



24
25
26
# File 'lib/cheat/responder.rb', line 24

def content_type
  @content_type
end