module Gon::EnvFinder

Constants

ENV_CONTROLLER_KEY
ENV_RESPONSE_KEY

Public Class Methods

controller_env(options = {}) click to toggle source
# 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) click to toggle source
# 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

Private Class Methods

current_gon() click to toggle source
# File lib/gon/env_finder.rb, line 39
def current_gon
  RequestStore.store[:gon]
end
right_extension?(extension, template_path) click to toggle source
# File lib/gon/env_finder.rb, line 35
def right_extension?(extension, template_path)
  File.extname(template_path) == ".#{extension}"
end