Module: Radiant::ResourceResponses::InstanceMethods

Defined in:
lib/radiant/resource_responses.rb

Instance Method Summary collapse

Instance Method Details

#response_for(action) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/radiant/resource_responses.rb', line 16

def response_for(action)
  responses = self.class.responses.send(action)
  respond_to do |wants|
    responses.each_format do |f, format_block|
      if format_block
        wants.send(f, &wrap(format_block))
      else
        wants.send(f)
      end
    end
    responses.each_published do |pub, pub_block|
      wants.send(pub, &wrap(pub_block))
    end
    if responses.default
      wants.any(&wrap(responses.default))
    else
      wants.any
    end
  end
end

#wrap(proc) ⇒ Object



37
38
39
40
41
42
# File 'lib/radiant/resource_responses.rb', line 37

def wrap(proc)
  # Makes sure our response blocks get evaluated in the right context
  lambda do
    instance_eval(&proc)
  end
end