Module: Strategize::Policy::ClassMethods

Defined in:
lib/strategize/policies/policy.rb

Overview

These methods will be placed on the class that includes the Policy module.

Instance Method Summary collapse

Instance Method Details

#operation(name = :default, &block) ⇒ void

This method returns an undefined value.

Define and add an [Operation] to the [OperationGroup] container

Parameters:

  • name (Symbol) (defaults to: :default)

    the name of the context for the operation

  • block (Proc)

    the code block to execute



43
44
45
# File 'lib/strategize/policies/policy.rb', line 43

def operation(name = :default, &block)
  operations.add(name, block)
end

#operationsOperationGroup

Get the [OperationGroup] container that has all the operations defined on the policy

Returns:



25
26
27
# File 'lib/strategize/policies/policy.rb', line 25

def operations
  @operations ||= OperationGroup.new
end

#rule(name, predicate) ⇒ void

This method returns an undefined value.

Define and add a [Rule] to the [RuleGroup] container

Parameters:

  • name (Symbol)

    descriptive name for the rule

  • predicate (Proc)

    code to execute



34
35
36
# File 'lib/strategize/policies/policy.rb', line 34

def rule(name, predicate)
  rule_group.add(name, predicate)
end

#rule_groupRuleGroup

Get the [RuleGroup] container that has all the rules defined on the policy

Returns:



17
18
19
# File 'lib/strategize/policies/policy.rb', line 17

def rule_group
  @rule_group ||= RuleGroup.new
end