class DeclarativePolicy::Condition

A Condition is the data structure that is created by the `condition` declaration on DeclarativePolicy::Base. It is more or less just a struct of the data passed to that declaration. It holds on to the block to be instance_eval'd on a context (instance of Base) later, via compute.

Attributes

context_key[R]
description[R]
manual_score[R]
name[R]
scope[R]

Public Class Methods

new(name, opts = {}, &compute) click to toggle source
# File lib/declarative_policy/condition.rb, line 12
def initialize(name, opts = {}, &compute)
  @name = name
  @compute = compute
  @scope = opts.fetch(:scope, :normal)
  @description = opts.delete(:description)
  @context_key = opts[:context_key]
  @manual_score = opts.fetch(:score, nil)
end

Public Instance Methods

compute(context) click to toggle source
# File lib/declarative_policy/condition.rb, line 21
def compute(context)
  !!context.instance_eval(&@compute)
end
key() click to toggle source
# File lib/declarative_policy/condition.rb, line 25
def key
  "#{@context_key}/#{@name}"
end