Sha256: dba75480e18d07c3db4c4030411d633f422a65de38c76b8c37e63c796825e1fe

Contents?: true

Size: 814 Bytes

Versions: 6

Compression:

Stored size: 814 Bytes

Contents

module ExceptionallyBeautiful
  class Error
    attr_reader :status_code

    def initialize(status_code)
      @status_code = status_code.to_i
    end

    def title
      @title ||= pretty_error_translation(:title)
    end

    def message
      @message ||= pretty_error_translation(:message)
    end

    private

    def pretty_error_translation(key)
      I18n.t(key, :scope => translation_scope, :raise => true)
    rescue I18n::MissingTranslationData
      log("Translation missing: #{translation_scope}.#{key}. Falling back to defaults.")
      I18n.t(key, :scope => ExceptionallyBeautiful.translation_scope('default'))
    end

    def log(message)
      ExceptionallyBeautiful.log(message)
    end

    def translation_scope
      ExceptionallyBeautiful.translation_scope(status_code)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
exceptionally_beautiful-0.1.5 app/models/exceptionally_beautiful/error.rb
exceptionally_beautiful-0.1.4 app/models/exceptionally_beautiful/error.rb
exceptionally_beautiful-0.1.3 app/models/exceptionally_beautiful/error.rb
exceptionally_beautiful-0.1.2 app/models/exceptionally_beautiful/error.rb
exceptionally_beautiful-0.1.1 app/models/exceptionally_beautiful/error.rb
exceptionally_beautiful-0.1.0 app/models/exceptionally_beautiful/error.rb