Sha256: fc01d8df6d7ece1f3bd7a192f3dde4aa8b15c4734a13865208cbc215430a5940

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Dat

  # Internal. The value of a watched behavior.
  module Science
    class Result
      attr_reader :duration
      attr_reader :exception
      attr_reader :value

      def initialize(value, duration, exception)
        @duration  = duration
        @exception = exception
        @value     = value
      end

      def ==(other)
        return false unless other.is_a? Science::Result

        values_are_equal = other.value == value
        both_raised      = other.raised? && raised?
        neither_raised   = !other.raised? && !raised?

        exceptions_are_equivalent =
          both_raised && other.exception.class == self.exception.class &&
          other.exception.message == self.exception.message

        (values_are_equal && neither_raised) ||
          (both_raised && exceptions_are_equivalent)
      end

      def hash
        exception ^ value
      end

      def payload
        { :duration => duration, :exception => exception, :value => value }
      end

      def raised?
        !!exception
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dat-science-0.0.0 lib/dat/science/result.rb