Sha256: 1c7cea78796eea38ef17f1a902ecbe9411873c8f4ec55db13de9a6bdcac61ce2

Contents?: true

Size: 626 Bytes

Versions: 2

Compression:

Stored size: 626 Bytes

Contents

require 'i18n'

require 'errawr/error'
require 'errawr/mapper'
require 'errawr/version'

module Errawr
  I18n.load_path << "#{File.dirname(__FILE__)}/errawr/locales/en.yml"
  I18n.reload!
  
  def self.included(base)
    base.extend(ClassMethods)
  end
  
  module ClassMethods
    def error!(name, context = {})
      klass = Mapper[name] || Mapper[:unknown]
      klass.metadata.merge!(context.delete(:metadata) || {})
      klass.context.merge!(context)
      raise klass
    end

    def register!(key, options = {})
      Mapper.register!(key, options)
    end
  end
  
  extend ClassMethods
  
  register!(:unknown)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
errawr-1.1.5 lib/errawr.rb
errawr-1.1.4 lib/errawr.rb