class Strategize::PolicyEvaluationDigest

Represents a container for evaluations performed against each policy provided in the initializer

Attributes

evaluations[R]

@return [Array<PolicyEvaluation>] the evaluation for each policy

subject[R]

@return [Object] the subject the policy was executed against

Public Class Methods

new(evaluations, subject) click to toggle source

Create a new PolicyEvaluationDigest

@param evaluations [Array<PolicyEvaluation>] @param subject [Object] the subject the policies were executed against

# File lib/strategize/policies/policy_evaluation_digest.rb, line 15
def initialize(evaluations, subject)
  @evaluations = evaluations
  @subject = subject
end

Public Instance Methods

failed() click to toggle source

Return all the policies where one or more rules defined on the policy evaluated to false.

@return [Array<Policy>]

# File lib/strategize/policies/policy_evaluation_digest.rb, line 34
def failed
  @evaluations
    .select { |evaluation| evaluation.result == false }
    .map(&:policy)
end
passed() click to toggle source

Return all the policies where all the rules defined on the policy evaluated to true

@return [Array<Policy>]

# File lib/strategize/policies/policy_evaluation_digest.rb, line 24
def passed
  @evaluations
    .select { |evaluation| evaluation.result == true }
    .map(&:policy)
end