Class: Policy::Base::Or Private

Inherits:
Node
  • Object
show all
Defined in:
lib/policy/base/or.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 any of its parts is valid. #valid? method picks errors from its parts in case both are invalid.

Examples:

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

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

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 whether any part of composition is valid

Mutates the policy by adding #errors in case all parts are invalid. Doesn’t add #errors if any policy is valid.

Examples:

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

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

Returns:

  • (Boolean)


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

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