Class: Policy::Base::Xor Private

Inherits:
Node
  • Object
show all
Defined in:
lib/policy/base/xor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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.

Examples:

first.valid?  # => false
second.valid? # => false

composition = Policy::Base::Xor.new(first, second)
composition.valid?        # => false
composition.errors.empty? # => false

Instance Attribute Summary

Attributes inherited from Node

#policies

Instance Method Summary collapse

Methods inherited from Node

initialize, #new

Methods included from Policy::Base

#and, included, #or, #xor

Instance Method Details

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Examples:

first.valid?  # => false
second.valid? # => false

composition = Policy::Base::Xor.new(first, second)
composition.valid?        # => false
composition.errors.empty? # => false

Returns:

  • (Boolean)


31
32
33
# File 'lib/policy/base/xor.rb', line 31

def valid?
  super { return true if any_valid? && any_invalid? }
end