class Strategize::Configuration

Attributes

policy_evaluator[R]
rule_evaluator[R]

Public Class Methods

new() click to toggle source

Create a new instance of [Configuration] class.

# File lib/strategize/configuration.rb, line 6
def initialize
  @rule_evaluator = Strategize::RuleEvaluator
  @policy_evaluator = Strategize::PolicyEvaluator
end

Public Instance Methods

add_policy_group(name) { |policy_group| ... } click to toggle source

Add a policy group to the policy_groups hash

@param name [Symbol] a descriptive name for the [PolicyGroup] @param [Proc] the block of code detailing which [Policy] to add

# File lib/strategize/configuration.rb, line 48
def add_policy_group(name)
  policy_groups[name] = PolicyGroup.new unless policy_groups.key?(name)
  policy_group = policy_groups[name]
  yield(policy_group)
end
policy_evaluator=(evaluator) click to toggle source

Set the default class that is responsible for evaluating a [Policy]. The class must implement a method named evaluate that takes a subject and an array of policies.

@param evaluator [Object] implements evaluate method

# File lib/strategize/configuration.rb, line 29
def policy_evaluator=(evaluator)
  unless evaluator.new(rule_evaluator).respond_to?(:evaluate)
    raise Strategize::InvalidPolicyEvaluator, 'no evaluate method found'
  end

  @policy_evaluator = evaluator
end
policy_group(name) click to toggle source

Get a specific [PolicyGroup] that has been defined in [Configuration]

@param name [Symbol] the name of the policy-group that you want @return [PolicyGroup]

# File lib/strategize/configuration.rb, line 58
def policy_group(name)
  policy_groups[name]
end
policy_groups() click to toggle source

Get a hash of all the policies groups that have been defined

@return [Hash]

# File lib/strategize/configuration.rb, line 40
def policy_groups
  @policy_groups ||= {}
end
rule_evaluator=(evaluator) click to toggle source

Set the default class that is responsible for evaluating a [Rule]. The class must implement a method named evaluate that takes a subject and an array of rules.

@param evaluator [Object] implements evaluate method

# File lib/strategize/configuration.rb, line 16
def rule_evaluator=(evaluator)
  unless evaluator.new.respond_to?(:evaluate)
    raise Strategize::InvalidRuleEvaluator, 'no evaluate method found'
  end

  @rule_evaluator = evaluator
end