Sha256: 7081955bbecff03ef6edd01880afdd899d408b514af703172988d867f6528073

Contents?: true

Size: 794 Bytes

Versions: 9

Compression:

Stored size: 794 Bytes

Contents

module Shippo
  module Exceptions

    class Error < StandardError
      attr_accessor :message

      def initialize(thing = nil)
        if thing.is_a?(String)
          self.message = thing
        elsif thing.respond_to?(:message)
          self.message = thing.message
        else
          super(thing)
        end
      end

      def to_s_members
        %i()
      end

      def to_s
        out = super
        out << " (#{message}) " if message
        to_s_members.each do |member|
          out << member_to_s(member)
        end
        out
      end

      private

      def member_to_s(member)
        out   = ''
        value = self.send(member)
        out << "\n#{sprintf('%21s', member)}: '#{value}', " if value && (value != '')
        out
      end


    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shippo-4.0.0 lib/shippo/exceptions/error.rb
shippo-3.1.0 lib/shippo/exceptions/error.rb
shippo-3.0.1 lib/shippo/exceptions/error.rb
shippo-3.0.0 lib/shippo/exceptions/error.rb
shippo-2.0.8 lib/shippo/exceptions/error.rb
shippo-2.0.7 lib/shippo/exceptions/error.rb
shippo-2.0.6 lib/shippo/exceptions/error.rb
shippo-2.0.5 lib/shippo/exceptions/error.rb
shippo-2.0.4 lib/shippo/exceptions/error.rb