Sha256: 10adb3b5bb1c089e614b54796f31f1f9d334413ed9388d5bc736cbaa46a79b21

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

# encoding: utf-8

module Policy

  module Base

    # Composition of two policies
    #
    # The policy is valid if one of its parts is valid, while another is not.
    # {#valid?} method picks errors from its parts in case both are invalid.
    #
    # @example (see #valid?)
    #
    # @api private
    class Xor < Node

      # Checks if there is both valid and invalid parts are present
      #
      # Mutates the policy by adding {#errors} if all parts are invalid.
      # Doesn't add {#errors} if any part is valid.
      #
      # @example
      #   first.valid?  # => false
      #   second.valid? # => false
      #
      #   composition = Policy::Base::Xor.new(first, second)
      #   composition.valid?        # => false
      #   composition.errors.empty? # => false
      #
      # @return [Boolean]
      def valid?
        super { return true if any_valid? && any_invalid? }
      end

    end # class Xor

  end # module Base

end # module Policy

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
policy-2.0.0 lib/policy/base/xor.rb