Module: Attestor::Policy
- Extended by:
- Factory, Validations::ClassMethods
- Includes:
- Validations
- Included in:
- Node
- Defined in:
- lib/attestor/policy.rb,
lib/attestor/policy/or.rb,
lib/attestor/policy/and.rb,
lib/attestor/policy/not.rb,
lib/attestor/policy/xor.rb,
lib/attestor/policy/node.rb,
lib/attestor/policy/factory.rb,
lib/attestor/policy/negator.rb
Overview
API for policies that validate another objects
Defined Under Namespace
Modules: Factory Classes: And, Negator, Node, Not, Or, Xor
Class Method Summary collapse
- .included(klass) ⇒ Object
-
.new(*attributes, &block) { ... } ⇒ Class
Builds a policy class with given attributes.
Instance Method Summary collapse
-
#and(*others) ⇒ Object
Builds the AND composition of current policy with other policies.
-
#not ⇒ Attestor::Policy::Not
Negates the current policy.
-
#or(*others) ⇒ Object
Builds the OR composition of current policy with other policies.
-
#xor(*others) ⇒ Object
Builds the XOR composition of current policy with other policies.
Methods included from Validations::ClassMethods
validate, validates, validations, validators
Methods included from Validations
#invalid, #validate, #validate!
Class Method Details
.included(klass) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/attestor/policy.rb', line 12 def self.included(klass) klass.instance_eval do include Validations extend Factory end end |
.new(*attributes, &block) { ... } ⇒ Class
Builds a policy class with given attributes
32 33 34 35 36 37 |
# File 'lib/attestor/policy.rb', line 32 def self.new(*attributes, &block) Struct.new(*attributes) do include Policy class_eval(&block) if block_given? end end |
Instance Method Details
#and(policy, *others) ⇒ Attestor::Policy::And #and(policy) ⇒ Attestor::Policy::Negator
Builds the AND composition of current policy with other policies
67 68 69 |
# File 'lib/attestor/policy.rb', line 67 def and(*others) self.class.and(self, *others) end |
#not ⇒ Attestor::Policy::Not
Negates the current policy
42 43 44 |
# File 'lib/attestor/policy.rb', line 42 def not self.class.not(self) end |
#or(policy, *others) ⇒ Attestor::Policy::And #or(policy) ⇒ Attestor::Policy::Negator
Builds the OR composition of current policy with other policies
92 93 94 |
# File 'lib/attestor/policy.rb', line 92 def or(*others) self.class.or(self, *others) end |
#xor(policy, *others) ⇒ Attestor::Policy::And #xor(policy) ⇒ Attestor::Policy::Negator
Builds the XOR composition of current policy with other policies
117 118 119 |
# File 'lib/attestor/policy.rb', line 117 def xor(*others) self.class.xor(self, *others) end |