Module: Gon::EnvFinder

Defined in:
lib/gon/env_finder.rb

Constant Summary collapse

ENV_CONTROLLER_KEY =
'action_controller.instance'
ENV_RESPONSE_KEY =
'action_controller.rescue.response'

Class Method Summary collapse

Class Method Details

.controller_env(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/gon/env_finder.rb', line 8

def controller_env(options = {})
  options[:controller] ||
    (
      current_gon &&
      current_gon.env[ENV_CONTROLLER_KEY] ||
      current_gon.env[ENV_RESPONSE_KEY].
        instance_variable_get('@template').
        instance_variable_get('@controller')
    )
end

.template_path(options, extension) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gon/env_finder.rb', line 19

def template_path(options, extension)
  if options[:template]
    if right_extension?(extension, options[:template])
      options[:template]
    else
      [options[:template], extension].join('.')
    end
  else
    controller = controller_env(options).controller_path
    action = controller_env(options).action_name
    "app/views/#{controller}/#{action}.json.#{extension}"
  end
end