aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/compatibility.rb
blob: 0e869e4e8792b954e28438452ed877342737f3af (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
module ActionController
  module Compatibility
    extend ActiveSupport::Concern

    class ::ActionController::ActionControllerError < StandardError #:nodoc:
    end

    # Temporary hax
    included do
      ::ActionController::UnknownAction = ::AbstractController::ActionNotFound
      ::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError

      cattr_accessor :session_options
      self.session_options = {}

      cattr_accessor :allow_concurrency
      self.allow_concurrency = false

      cattr_accessor :relative_url_root
      self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']

      class << self
        delegate :default_charset=, :to => "ActionDispatch::Response"
        delegate :resources_path_names, :to => "ActionController::Routing::Routes"
        delegate :resources_path_names=, :to => "ActionController::Routing::Routes"
      end

      # cattr_reader :protected_instance_variables
      cattr_accessor :protected_instance_variables
      self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render
                                             @variables_added @request_origin @url
                                             @parent_controller @action_name
                                             @before_filter_chain_aborted @_headers @_params
                                             @_response)

      # Controls the resource action separator
      cattr_accessor :resource_action_separator
      self.resource_action_separator = "/"

      cattr_accessor :use_accept_header
      self.use_accept_header = true

      self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""

      cattr_accessor :consider_all_requests_local
      self.consider_all_requests_local = true

      # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
      # and images to a dedicated asset server away from the main web server. Example:
      #   ActionController::Base.asset_host = "http://assets.example.com"
      cattr_accessor :asset_host

      cattr_accessor :ip_spoofing_check
      self.ip_spoofing_check = true

      cattr_accessor :trusted_proxies
    end

    # For old tests
    def initialize_template_class(*) end
    def assign_shortcuts(*) end

    # TODO: Remove this after we flip
    def template
      @template ||= view_context
    end

    def process_action(*)
      template
      super
    end

    module ClassMethods
      def consider_all_requests_local
      end

      def rescue_action(env)
        raise env["action_dispatch.rescue.exception"]
      end

      # Defines the storage option for cached fragments
      def cache_store=(store_option)
        @@cache_store = ActiveSupport::Cache.lookup_store(store_option)
      end
    end

    def render_to_body(options)
      if options.is_a?(Hash) && options.key?(:template)
        options[:template].sub!(/^\//, '')
      end

      options[:text] = nil if options.delete(:nothing) == true
      options[:text] = " " if options.key?(:text) && options[:text].nil?

      super || " "
    end

    def _handle_method_missing
      method_missing(@_action_name.to_sym)
    end

    def method_for_action(action_name)
      super || (respond_to?(:method_missing) && "_handle_method_missing")
    end

    def _find_layout(name, details)
      details[:prefix] = nil if name =~ /\blayouts/
      super
    end

    # Move this into a "don't run in production" module
    def _default_layout(details, require_layout = false)
      super
    rescue ActionView::MissingTemplate
      _find_layout(_layout({}), {})
      nil
    end

    def performed?
      response_body
    end

    # ==== Request only view path switching ====
    def append_view_path(path)
      view_paths.push(*path)
    end

    def prepend_view_path(path)
      view_paths.unshift(*path)
    end

    def view_paths
      view_context.view_paths
    end
  end
end