strategize 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42524de68454e2ad718b1849668425b46440fbac
4
- data.tar.gz: 0191dd00cce17dbc790d18f14646ffa56a43dada
3
+ metadata.gz: d0c40c7d4e864ff616e141efe128f8a6f8f083cd
4
+ data.tar.gz: d63ed781fda44b7d40c094f76a8fc11fcda7b2e2
5
5
  SHA512:
6
- metadata.gz: 6cf723d3e305c0f90fdce8cb878f51bd688477101f20bf82daa3b340e95de8c2146274a592860b6106492bfb1a9fcf9f3586ec27f856645a5d2135aa348e009d
7
- data.tar.gz: ac6bd23200464784123842b3c84c7986f90cdfc96fa3b7e597a6ee17e50be42e4cb3b41fa37de51befb9acf2db48e88f3b3de2f46138441127e90fca2d6f1fb8
6
+ metadata.gz: e58b4dfaffbd76b72bf1a611e94a7fb09d163d8d36050db150f9113bf64d10c718d2d3d530c768cca975d6189da4ba84ff62b5043087eb62dbb9552e341bf47e
7
+ data.tar.gz: 0b7c23d50adc27568b82ae98034ce230fc57df357bf671bd9f917744a73ab3d35ca3efef31709a31ea1c0420ad8232851666d22107c1370a38e15075e15f6f87
data/lib/strategize.rb CHANGED
@@ -1,20 +1,54 @@
1
1
  module Strategize
2
2
  # Rules
3
- autoload :Rule, 'strategize/rules/rule'
4
- autoload :RuleGroup, 'strategize/rules/rule_group'
5
- autoload :RuleResult, 'strategize/rules/rule_result'
6
- autoload :RuleResultCollection, 'strategize/rules/rule_result_collection'
3
+ autoload :Rule, 'strategize/rules/rule'
4
+ autoload :RuleGroup, 'strategize/rules/rule_group'
5
+ autoload :RuleEvaluation, 'strategize/rules/rule_evaluation'
6
+ autoload :RuleEvaluationDigest, 'strategize/rules/rule_evaluation_digest'
7
7
 
8
8
  # Policies
9
- autoload :Policy, 'strategize/policies/policy'
10
- autoload :PolicyGroup, 'strategize/policies/policy_group'
11
- autoload :PolicyResult, 'strategize/policies/policy_result'
12
- autoload :PolicyResultCollection, 'strategize/policies/policy_result_collection'
9
+ autoload :Policy, 'strategize/policies/policy'
10
+ autoload :PolicyGroup, 'strategize/policies/policy_group'
11
+ autoload :PolicyEvaluation, 'strategize/policies/policy_evaluation'
12
+ autoload :PolicyEvaluationDigest, 'strategize/policies/policy_evaluation_digest'
13
+
14
+ # Evaluators
15
+ autoload :RuleEvaluator, 'strategize/evaluators/rule_evaluator'
16
+ autoload :PolicyEvaluator, 'strategize/evaluators/policy_evaluator'
13
17
 
14
18
  # Operations
15
- autoload :Operation, 'strategize/operations/operation'
16
- autoload :OperationGroup, 'strategize/operations/operation_group'
19
+ autoload :Operation, 'strategize/operations/operation'
20
+ autoload :OperationGroup, 'strategize/operations/operation_group'
17
21
 
18
22
  # Exceptions
19
- autoload :NotPolicyError, 'strategize/exceptions'
23
+ autoload :NotPolicyError, 'strategize/exceptions'
24
+ autoload :InvalidPredicateError, 'strategize/exceptions'
25
+ autoload :InvalidFunctionError, 'strategize/exceptions'
26
+ autoload :InvalidRuleEvaluator, 'strategize/exceptions'
27
+ autoload :InvalidPolicyEvaluator, 'strategize/exceptions'
28
+
29
+ # Configuration
30
+ autoload :Configuration, 'strategize/configuration'
31
+
32
+ class << self
33
+ # Get the configuration object for Strategize
34
+ #
35
+ # @return [Configuration]
36
+ def configuration
37
+ @configuration ||= Configuration.new
38
+ end
39
+
40
+ # Overwrite the current [Configuration] object
41
+ # with a new [Configuration] instance, which
42
+ # returns everything to default
43
+ def reset_configuration
44
+ @configuration = Configuration.new
45
+ end
46
+
47
+ # Pass a block of code that is executed against the
48
+ # [Configuration] instance
49
+ def configure
50
+ configuration = self.configuration
51
+ yield(configuration)
52
+ end
53
+ end
20
54
  end
@@ -0,0 +1,62 @@
1
+ module Strategize
2
+ class Configuration
3
+ attr_reader :rule_evaluator, :policy_evaluator
4
+
5
+ # Create a new instance of [Configuration] class.
6
+ def initialize
7
+ @rule_evaluator = Strategize::RuleEvaluator
8
+ @policy_evaluator = Strategize::PolicyEvaluator
9
+ end
10
+
11
+ # Set the default class that is responsible for evaluating
12
+ # a [Rule]. The class must implement a method named evaluate
13
+ # that takes a subject and an array of rules.
14
+ #
15
+ # @param evaluator [Object] implements evaluate method
16
+ def rule_evaluator=(evaluator)
17
+ unless evaluator.new.respond_to?(:evaluate)
18
+ raise Strategize::InvalidRuleEvaluator, 'no evaluate method found'
19
+ end
20
+
21
+ @rule_evaluator = evaluator
22
+ end
23
+
24
+ # Set the default class that is responsible for evaluating
25
+ # a [Policy]. The class must implement a method named evaluate
26
+ # that takes a subject and an array of policies.
27
+ #
28
+ # @param evaluator [Object] implements evaluate method
29
+ def policy_evaluator=(evaluator)
30
+ unless evaluator.new(rule_evaluator).respond_to?(:evaluate)
31
+ raise Strategize::InvalidPolicyEvaluator, 'no evaluate method found'
32
+ end
33
+
34
+ @policy_evaluator = evaluator
35
+ end
36
+
37
+ # Get a hash of all the policies groups that have been defined
38
+ #
39
+ # @return [Hash]
40
+ def policy_groups
41
+ @policy_groups ||= {}
42
+ end
43
+
44
+ # Add a policy group to the policy_groups hash
45
+ #
46
+ # @param name [Symbol] a descriptive name for the [PolicyGroup]
47
+ # @param [Proc] the block of code detailing which [Policy] to add
48
+ def add_policy_group(name)
49
+ policy_groups[name] = PolicyGroup.new unless policy_groups.key?(name)
50
+ policy_group = policy_groups[name]
51
+ yield(policy_group)
52
+ end
53
+
54
+ # Get a specific [PolicyGroup] that has been defined in [Configuration]
55
+ #
56
+ # @param name [Symbol] the name of the policy-group that you want
57
+ # @return [PolicyGroup]
58
+ def policy_group(name)
59
+ policy_groups[name]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,17 @@
1
+ module Strategize
2
+ class PolicyEvaluator
3
+ def initialize(rule_evaluator)
4
+ @rule_evaluator = rule_evaluator
5
+ end
6
+
7
+ def evaluate(*policies, subject)
8
+ policies.flatten!
9
+ results = policies.map do |policy|
10
+ rules = policy.rule_group.rules
11
+ rule_digest = @rule_evaluator.evaluate(subject, rules)
12
+ PolicyEvaluation.new(policy, rule_digest)
13
+ end
14
+ PolicyEvaluationDigest.new(results, subject)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Strategize
2
+ class RuleEvaluator
3
+ # Given an array of rules, evaluates each rule and returns
4
+ # the results
5
+ #
6
+ # @param rules [Array<Rule>] rules to be evaluated
7
+ # @param subject [Object] the object to evaluate rules against
8
+ def evaluate(subject, *rules)
9
+ rules.flatten!
10
+ results = rules.map do |rule|
11
+ RuleEvaluation.new(rule, rule.evaluate(subject))
12
+ end
13
+ RuleEvaluationDigest.new(results, subject)
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,16 @@
1
1
  module Strategize
2
2
  # Raised when a class does not include
3
- # the Stategize::Policy module.
3
+ # the Stategize::Policy module.
4
4
  NotPolicyError = Class.new(RuntimeError)
5
+
6
+ # Raised when an object that does not respond to
7
+ # call is provided in [Rule] initialization.
8
+ InvalidPredicateError = Class.new(RuntimeError)
9
+
10
+ # Raised when an object that does not respond to
11
+ # call is provided in [Operation] initialization.
12
+ InvalidFunctionError = Class.new(RuntimeError)
13
+
14
+ InvalidRuleEvaluator = Class.new(RuntimeError)
15
+ InvalidPolicyEvaluator = Class.new(RuntimeError)
5
16
  end
@@ -18,6 +18,10 @@ module Strategize
18
18
  # @param function [Proc] the code to be executed
19
19
  # @return [Operation]
20
20
  def initialize(name, function)
21
+ unless function.respond_to?(:call)
22
+ raise InvalidFunctionError, 'Invalid function in Operation'
23
+ end
24
+
21
25
  @name = name
22
26
  @function = function
23
27
  end
@@ -25,10 +25,8 @@ module Strategize
25
25
  # @param subject [Hash] a hash of operation names and subjects
26
26
  def run(subjects)
27
27
  the_subjects = subjects
28
+ the_subjects = build_subjects_hash(subjects) unless subjects.is_a?(Hash)
28
29
 
29
- if !subjects.is_a?(Hash)
30
- the_subjects = build_subjects_hash(subjects)
31
- end
32
30
 
33
31
  @operations.each do |operation|
34
32
  subject = the_subjects[operation.name]
@@ -1,6 +1,6 @@
1
1
  module Strategize
2
- # The policy module allows you to define rules and an operation on
3
- # any class that it is included on.
2
+ # The policy module allows you to define rules and operations on
3
+ # any class that it is included on
4
4
  module Policy
5
5
  def self.included(base)
6
6
  base.extend(ClassMethods)
@@ -10,31 +10,32 @@ module Strategize
10
10
  # These methods will be placed on the class that includes
11
11
  # the Policy module.
12
12
  module ClassMethods
13
- # Get all the rules defined on this policy
13
+ # Get the [RuleGroup] container that has all the
14
+ # rules defined on the policy
14
15
  #
15
16
  # @return [RuleGroup]
16
- def rules
17
- @rules ||= RuleGroup.new
17
+ def rule_group
18
+ @rule_group ||= RuleGroup.new
18
19
  end
19
20
 
20
- # Get all the operations defined on this policy.
21
+ # Get the [OperationGroup] container that has all the
22
+ # operations defined on the policy
21
23
  #
22
24
  # @return [OperationGroup]
23
25
  def operations
24
26
  @operations ||= OperationGroup.new
25
27
  end
26
28
 
27
- # Define a rule for a policy
29
+ # Define and add a [Rule] to the [RuleGroup] container
28
30
  #
29
31
  # @param name [Symbol] descriptive name for the rule
30
32
  # @param predicate [Proc] code to execute
31
33
  # @return [void]
32
34
  def rule(name, predicate)
33
- rules.add(name, predicate)
35
+ rule_group.add(name, predicate)
34
36
  end
35
37
 
36
- # Define a block of code to run when you call the process
37
- # method
38
+ # Define and add an [Operation] to the [OperationGroup] container
38
39
  #
39
40
  # @param name [Symbol] the name of the context for the operation
40
41
  # @param block [Proc] the code block to execute
@@ -0,0 +1,26 @@
1
+ module Strategize
2
+ # Provides information on a single policy evaluation.
3
+ # This includes the policy that was evaluated and
4
+ # the evaluation digest for the rules defined on
5
+ # the policy.
6
+ class PolicyEvaluation
7
+ attr_reader :policy, :rule_digest
8
+
9
+ # Create a new PolicyEvaluation
10
+ #
11
+ # @param policy [Policy]
12
+ # @param rule_result_collection [RuleEvaluationDigest]
13
+ # @return [PolicyResult]
14
+ def initialize(policy, rule_digest)
15
+ @policy = policy
16
+ @rule_digest = rule_digest
17
+ end
18
+
19
+ # Determine if all the rules defined on the policy
20
+ # evaluated to true.
21
+ # @return [Boolean]
22
+ def result
23
+ @rule_digest.result
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module Strategize
2
+ # Represents a container for evaluations performed against each
3
+ # policy provided in the initializer
4
+ class PolicyEvaluationDigest
5
+ # @return [Array<PolicyEvaluation>] the evaluation for each policy
6
+ attr_reader :evaluations
7
+
8
+ # @return [Object] the subject the policy was executed against
9
+ attr_reader :subject
10
+
11
+ # Create a new PolicyEvaluationDigest
12
+ #
13
+ # @param evaluations [Array<PolicyEvaluation>]
14
+ # @param subject [Object] the subject the policies were executed against
15
+ def initialize(evaluations, subject)
16
+ @evaluations = evaluations
17
+ @subject = subject
18
+ end
19
+
20
+ # Return all the policies where all the rules defined on the
21
+ # policy evaluated to true
22
+ #
23
+ # @return [Array<Policy>]
24
+ def passed
25
+ @evaluations
26
+ .select { |evaluation| evaluation.result == true }
27
+ .map(&:policy)
28
+ end
29
+
30
+ # Return all the policies where one or more rules defined on the
31
+ # policy evaluated to false.
32
+ #
33
+ # @return [Array<Policy>]
34
+ def failed
35
+ @evaluations
36
+ .select { |evaluation| evaluation.result == false }
37
+ .map(&:policy)
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,5 @@
1
1
  module Strategize
2
- # The PolicyGroup allows you to evaluate a subject against
3
- # multiple policies.
2
+ # A collection of policies.
4
3
  class PolicyGroup
5
4
  attr_reader :policies
6
5
 
@@ -18,18 +17,6 @@ module Strategize
18
17
  @policies.push(policy)
19
18
  end
20
19
 
21
- # Evaluate each policy against a given subject.
22
- #
23
- # @param subject [Object]
24
- # @return [PolicyResultCollection]
25
- def evaluate(subject)
26
- results = @policies.map do |policy|
27
- result_collection = policy.rules.evaluate(subject)
28
- PolicyResult.new(policy, result_collection)
29
- end
30
- PolicyResultCollection.new(results, subject)
31
- end
32
-
33
20
  private
34
21
 
35
22
  # Check if a policy includes the Policy module
@@ -7,7 +7,7 @@ module Strategize
7
7
  #
8
8
  # Evaluate a rule
9
9
  # rule = Rule.new :rule_name, -> { true }
10
- # rule.evaluate(nil) #=> true
10
+ # rule.evaluate(nil) #=> true
11
11
  class Rule
12
12
  attr_reader :name, :predicate
13
13
 
@@ -16,6 +16,10 @@ module Strategize
16
16
  # @param name [Symbol] a descriptive name for the rule
17
17
  # @param predicate [Proc] code block to be executed
18
18
  def initialize(name, predicate)
19
+ unless predicate.respond_to?(:call)
20
+ raise InvalidPredicateError, 'Invalid predicate function passed'
21
+ end
22
+
19
23
  @name = name
20
24
  @predicate = predicate
21
25
  end
@@ -0,0 +1,10 @@
1
+ module Strategize
2
+ class RuleEvaluation
3
+ attr_reader :rule, :result
4
+
5
+ def initialize(rule, result)
6
+ @rule = rule
7
+ @result = result
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ module Strategize
2
+ class RuleEvaluationDigest
3
+ attr_reader :evaluations, :subject
4
+
5
+ def initialize(evaluations, subject)
6
+ @evaluations = evaluations
7
+ @subject = subject
8
+ end
9
+
10
+ def result
11
+ @evaluations.all?(&:result)
12
+ end
13
+
14
+ def rules
15
+ @evaluations.map(&:rule)
16
+ end
17
+
18
+ def passed
19
+ @evaluations
20
+ .select { |evaluation| evaluation.result == true }
21
+ .map(&:rule)
22
+ end
23
+
24
+ def failed
25
+ @evaluations
26
+ .select { |evaluation| evaluation.result == false }
27
+ .map(&:rule)
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module Strategize
2
- # The RuleGroup allows you evaluate multiple rules against one subject.
2
+ # A wrapper around an array of rules
3
3
  class RuleGroup
4
4
  attr_reader :rules
5
5
 
@@ -10,7 +10,7 @@ module Strategize
10
10
  @rules = rules
11
11
  end
12
12
 
13
- # Add [Rule] to be evaluated
13
+ # Add [Rule] to the group
14
14
  #
15
15
  # @param name [Symbol] a descriptive name for the rule
16
16
  # @param predicate [Lambda] a function that returns true or false
@@ -18,16 +18,8 @@ module Strategize
18
18
  @rules.push(Rule.new(name, predicate))
19
19
  end
20
20
 
21
- # Evaluate all rules in group and return a collection
22
- # of the results.
23
- #
24
- # @param subject [Object] object to evaluate rules against
25
- # @return [RuleResultCollection] evaluation results
26
- def evaluate(subject)
27
- results = @rules.map do |rule|
28
- RuleResult.new(rule, rule.evaluate(subject))
29
- end
30
- RuleResultCollection.new(results, subject)
21
+ def <<(name, predicate)
22
+ add(name, predicate)
31
23
  end
32
24
  end
33
25
  end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Minitest::Test
4
+ def test_configuration_is_available
5
+ config = Strategize.configuration
6
+ refute config.nil?
7
+ end
8
+
9
+ def test_can_configure_from_block
10
+ Strategize.configure do |config|
11
+ config.rule_evaluator = TestRuleEvaluator
12
+ end
13
+ end
14
+
15
+ def test_can_add_policy_group
16
+ Strategize.configure do |config|
17
+ config.add_policy_group(:omniauth) do |group|
18
+ group.add DummyPolicy
19
+ end
20
+ end
21
+
22
+ refute Strategize.configuration.policy_groups.empty?
23
+ end
24
+
25
+ def test_can_get_policy_group
26
+ Strategize.configure do |config|
27
+ config.add_policy_group(:omniauth) do |group|
28
+ group.add DummyPolicy
29
+ end
30
+ end
31
+
32
+ policy_group = Strategize.configuration.policy_group(:omniauth)
33
+ policies = policy_group.policies
34
+
35
+ assert policy_group.is_a?(Strategize::PolicyGroup)
36
+ assert policies.include?(DummyPolicy)
37
+ end
38
+
39
+ def teardown
40
+ Strategize.reset_configuration
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strategize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jdmorlan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-reporters
@@ -45,17 +45,21 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - lib/strategize.rb
48
+ - lib/strategize/configuration.rb
49
+ - lib/strategize/evaluators/policy_evaluator.rb
50
+ - lib/strategize/evaluators/rule_evaluator.rb
48
51
  - lib/strategize/exceptions.rb
49
52
  - lib/strategize/operations/operation.rb
50
53
  - lib/strategize/operations/operation_group.rb
51
54
  - lib/strategize/policies/policy.rb
55
+ - lib/strategize/policies/policy_evaluation.rb
56
+ - lib/strategize/policies/policy_evaluation_digest.rb
52
57
  - lib/strategize/policies/policy_group.rb
53
- - lib/strategize/policies/policy_result.rb
54
- - lib/strategize/policies/policy_result_collection.rb
55
58
  - lib/strategize/rules/rule.rb
59
+ - lib/strategize/rules/rule_evaluation.rb
60
+ - lib/strategize/rules/rule_evaluation_digest.rb
56
61
  - lib/strategize/rules/rule_group.rb
57
- - lib/strategize/rules/rule_result.rb
58
- - lib/strategize/rules/rule_result_collection.rb
62
+ - test/configuration_test.rb
59
63
  - test/test_helper.rb
60
64
  homepage: https://github.com/jdmorlan/strategize
61
65
  licenses:
@@ -82,5 +86,5 @@ signing_key:
82
86
  specification_version: 4
83
87
  summary: Validate rules and perform operations
84
88
  test_files:
89
+ - test/configuration_test.rb
85
90
  - test/test_helper.rb
86
- has_rdoc:
@@ -1,33 +0,0 @@
1
- module Strategize
2
- # A PolicyResult is returned when you evaluate
3
- # a PolicyGroup and allows you to view the
4
- # RuleResultCollection and whether the policy
5
- # was valid (all rules returned true)
6
- class PolicyResult
7
- attr_reader :policy, :rule_group, :subject
8
-
9
- # Create a new PolicyEvaluation
10
- #
11
- # @param policy [Policy]
12
- # @param rule_result_collection [RuleResultCollection]
13
- # @return [PolicyResult]
14
- def initialize(policy, rule_result_collection)
15
- @policy = policy
16
- @rule_result_collection = rule_result_collection
17
- end
18
-
19
- # Check if all the rules for the policy evaluated to true
20
- #
21
- # @return [Boolean]
22
- def valid?
23
- @rule_result_collection.all_valid?
24
- end
25
-
26
- # Get the results for rules on the policy
27
- #
28
- # @return [RuleResultCollection]
29
- def rules
30
- @rule_result_collection
31
- end
32
- end
33
- end
@@ -1,33 +0,0 @@
1
- module Strategize
2
- # A wrapper for an array of PolicyResult instances.
3
- class PolicyResultCollection
4
- # @return [Array<PolicyResult>] the policy results for each policy
5
- attr_reader :items
6
-
7
- # @return [Object] the subject the policy was executed against
8
- attr_reader :subject
9
-
10
- # Create a new PolicyResultCollection
11
- #
12
- # @param policy_results [Array<PolicyResult]
13
- # @param subject [Object] the subject the policies were executed against
14
- def initialize(policy_results, subject)
15
- @items = policy_results
16
- @subject = subject
17
- end
18
-
19
- # Get an array of the PolicyResults that are valid, or return true
20
- #
21
- # @return [Array<PolicyResult>]
22
- def passed
23
- @items.select(&:valid)
24
- end
25
-
26
- # Get an array of the PolicyResults that are invalid, or return false
27
- #
28
- # @return [Array<PolicyResult>]
29
- def failed
30
- @items.select { |rule| !rule.valid? }
31
- end
32
- end
33
- end
@@ -1,18 +0,0 @@
1
- module Strategize
2
- # A RuleResult represents the evaluation result, which gives
3
- # you access to the Rule and whether it was valid or not.
4
- class RuleResult
5
- attr_reader :rule, :valid
6
-
7
- # Create a new RuleResult which provides details on
8
- # the evaluation of a rule.
9
- #
10
- # @param rule [Rule] the evaluated rule
11
- # @param valid [Boolean] the result of the executed rule
12
- # @return [RuleResult]
13
- def initialize(rule, valid)
14
- @rule = rule
15
- @valid = valid
16
- end
17
- end
18
- end
@@ -1,45 +0,0 @@
1
- module Strategize
2
- # Represents a collection of RuleResults, which lets you see
3
- # what rules passed, failed, etc.
4
- class RuleResultCollection
5
- attr_reader :items, :subject
6
-
7
- # Create a new RuleResultCollection
8
- #
9
- # @param rule_results [Array<RuleResult>]
10
- # @param subject [Object]
11
- # @return [RuleResultCollection]
12
- def initialize(rule_results, subject)
13
- @items = rule_results
14
- @subject = subject
15
- end
16
-
17
- # Iterate over each [RuleResult] in the items Array.
18
- #
19
- # @param block [Proc]
20
- def each(&block)
21
- @items.each { |item| block.call(item) }
22
- end
23
-
24
- # Returns if all rules evaluated to true
25
- #
26
- # @return [Boolean]
27
- def all_valid?
28
- @items.all?(&:valid)
29
- end
30
-
31
- # Returns all rules that evaluated to true
32
- #
33
- # @return [Array<RuleResult>]
34
- def passed
35
- @items.select(&:valid)
36
- end
37
-
38
- # Returns all rules that evaluated to false
39
- #
40
- # @return [Array<RuleResult>]
41
- def failed
42
- @items.select { |rule| !rule.valid }
43
- end
44
- end
45
- end