aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/base/responder.rb
blob: 989f82444b28adbf62902c4307c214c457cf2e17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module ActionController
  module Responder
    def self.included(klass)
      klass.extend ClassMethods
    end
    
    private
    def render_for_text(text = nil, append_response = false) #:nodoc:
      @performed_render = true

      if append_response
        response.body ||= ''
        response.body << text.to_s
      else
        response.body = case text
          when Proc then text
          when nil  then " " # Safari doesn't pass the headers of the return if the response is zero length
          else           text.to_s
        end
      end
    end
    
    # Returns a set of the methods defined as actions in your controller
    def action_methods
      self.class.action_methods
    end
    
    module ClassMethods
      def action_methods
        @action_methods ||=
          # All public instance methods of this class, including ancestors
          public_instance_methods(true).map { |m| m.to_s }.to_set -
          # Except for public instance methods of Base and its ancestors
          Base.public_instance_methods(true).map { |m| m.to_s } +
          # Be sure to include shadowed public instance methods of this class
          public_instance_methods(false).map { |m| m.to_s } -
          # And always exclude explicitly hidden actions
          hidden_actions
      end
    end
  end
end