class SimplificatorInfrastructure::ErrorSummary

Attributes

env[R]

Public Class Methods

new(env) click to toggle source
# File lib/simplificator_infrastructure/error_summary.rb, line 6
def initialize(env)
  @env = env
end

Public Instance Methods

exception() click to toggle source

extracts the exception from env

# File lib/simplificator_infrastructure/error_summary.rb, line 16
def exception
  env['action_dispatch.exception']
end
locale() click to toggle source

tries to detect locale based on available_locales and a locale which is in the path, in params (:locale), in the accept header or default

# File lib/simplificator_infrastructure/error_summary.rb, line 26
def locale
  locale_from_path || locale_from_params || locale_from_header || locale_default
end
params() click to toggle source
# File lib/simplificator_infrastructure/error_summary.rb, line 20
def params
  env['action_dispatch.request.parameters']
end
status_code() click to toggle source

detects the status code based on the exception that was thrown

# File lib/simplificator_infrastructure/error_summary.rb, line 11
def status_code
  @status_code ||= ActionDispatch::ExceptionWrapper.new(env, exception).status_code
end

Private Instance Methods

locale_from_path() click to toggle source
# File lib/simplificator_infrastructure/error_summary.rb, line 40
def locale_from_path
  match = request_path.try(:match, /\A\/([a-z]{2})\/.*\z/)
  locale = match[1].try(:to_sym) if match
  available_locale_or_nil(locale)
end
request() click to toggle source
# File lib/simplificator_infrastructure/error_summary.rb, line 32
def request
  @request ||= Rack::Request.new(env)
end
request_path() click to toggle source
# File lib/simplificator_infrastructure/error_summary.rb, line 36
def request_path
  env['REQUEST_PATH']
end