Sha256: dbe46a303d5fbe93b8c29c769f9a398abb9f6a02a0681ddca9e5d51bd2cd4596

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

require "i18n"

module Scorpion
  class Error < StandardError

    private

      def translate( key, **args )
        I18n.translate key, args.merge( scope: [:scorpion, :errors, :messages] )
      end

  end

  class UnsuccessfulHunt < Error
    attr_reader :contract

    def initialize( contract )
      @contract = contract

      super translate( :unsuccessful_hunt, contract: contract )
    end
  end

  class ArityMismatch < Error
    def initialize( block, expected_count )
      super translate( :arity_mismatch, expected: expected_count, actual: block.arity )
    end
  end

  class BuilderRequiredError < Error
    def initialize( message = nil )
      super ( message || translate( :builder_required ) )
    end
  end

  class ContractMismatchError < Error
    def initialize( message_or_module = nil, initializer_attr = nil, injected_attr = nil )
      if message_or_module.is_a?( Module )
        super translate( :contract_mismatch, module: message_or_module,
                                             name: initializer_attr.name,
                                             from: initializer_attr.contract,
                                             to: injected_attr.contract )
      else
        super ( message || translate( :contract_mismatch ) )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.10 lib/scorpion/error.rb
scorpion-ioc-1.0.8 lib/scorpion/error.rb
scorpion-ioc-1.0.7 lib/scorpion/error.rb
scorpion-ioc-1.0.6 lib/scorpion/error.rb
scorpion-ioc-1.0.4 lib/scorpion/error.rb
scorpion-ioc-1.0.3 lib/scorpion/error.rb
scorpion-ioc-1.0.2 lib/scorpion/error.rb
scorpion-ioc-1.0.1 lib/scorpion/error.rb
scorpion-ioc-1.0.0 lib/scorpion/error.rb