Sha256: d460efccb8678bf65043c1cb36dac68018050f43b40616a58569db7b5b71dced

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

class SimplificatorInfrastructure::ErrorSummary
  include SimplificatorInfrastructure::LocaleDetection

  attr_reader :env

  def initialize(env)
    @env = env
  end

  # detects the status code based on the exception that was thrown
  def status_code
    @status_code ||= ActionDispatch::ExceptionWrapper.new(env, exception).status_code
  end

  # extracts the exception from env
  def exception
    env['action_dispatch.exception']
  end

  def params
    env['action_dispatch.request.parameters']
  end

  # 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
  def locale
    locale_from_path || locale_from_params || locale_from_header || locale_default
  end

  private

  def request
    @request ||= Rack::Request.new(env)
  end

  def request_path
    env['REQUEST_PATH']
  end

  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

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simplificator_infrastructure-0.1.1 lib/simplificator_infrastructure/error_summary.rb
simplificator_infrastructure-0.1.0 lib/simplificator_infrastructure/error_summary.rb
simplificator_infrastructure-0.0.11 lib/simplificator_infrastructure/error_summary.rb
simplificator_infrastructure-0.0.10 lib/simplificator_infrastructure/error_summary.rb