Sha256: de292b465b2db53a7d1e163d8c06048d4dc64da386e50deceb401bda7ab02baa

Contents?: true

Size: 944 Bytes

Versions: 4

Compression:

Stored size: 944 Bytes

Contents

# encoding: utf-8

module Attestor

  # Describes the result, returned by safe validation
  class Report

    # @private
    def initialize(object, error = nil)
      @object = object
      @error  = error
      freeze
    end

    # @!attribute [r] object
    # The object being validated
    #
    # @return [Object]
    attr_reader :object

    # @!attribute [r] error
    # The exception raised by validation
    #
    # @return [Attestor::InvalidError] if validation fails
    # @return [nil] if validation passes
    attr_reader :error

    # Checks whether validation passes
    #
    # @return [Boolean]
    def valid?
      error.blank?
    end

    # Checks whether validation fails
    #
    # @return [Boolean]
    def invalid?
      !valid?
    end

    # Returns the list of error messages
    #
    # @return [Array<String>]
    def messages
      error ? error.messages : []
    end

  end # class Report

end # module Attestor

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
attestor-2.2.1 lib/attestor/report.rb
attestor-2.2.0 lib/attestor/report.rb
attestor-2.1.0 lib/attestor/report.rb
attestor-2.0.0 lib/attestor/report.rb