class DeclarativePolicy::RuleDsl

The DSL evaluation context inside rule { … } blocks. Responsible for creating and combining Rule objects.

See Base.rule

Public Class Methods

new(context_class) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 9
def initialize(context_class)
  @context_class = context_class
end

Public Instance Methods

all?(*rules) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 17
def all?(*rules)
  Rule::And.make(rules)
end
any?(*rules) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 21
def any?(*rules)
  Rule::Or.make(rules)
end
can?(ability) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 13
def can?(ability)
  Rule::Ability.new(ability)
end
cond(condition) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 29
def cond(condition)
  Rule::Condition.new(condition)
end
delegate(delegate_name, condition) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 33
def delegate(delegate_name, condition)
  Rule::DelegatedCondition.new(delegate_name, condition)
end
method_missing(msg, *args) click to toggle source
Calls superclass method
# File lib/declarative_policy/rule_dsl.rb, line 37
def method_missing(msg, *args)
  return super unless args.empty? && !block_given?

  if @context_class.delegations.key?(msg)
    DelegateDsl.new(self, msg)
  else
    cond(msg.to_sym)
  end
end
none?(*rules) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 25
def none?(*rules)
  ~Rule::Or.new(rules)
end
respond_to_missing?(symbol, include_all) click to toggle source
# File lib/declarative_policy/rule_dsl.rb, line 47
def respond_to_missing?(symbol, include_all)
  true
end