class Dry::Ability::Container

Constants

MAPPING_NSFN
RULES_NSFN

Public Instance Methods

key_candidates(action, subject) click to toggle source
# File lib/dry/ability/container.rb, line 33
def key_candidates(action, subject)
  subject, action = mappings(:subject, subject), mappings(:action, action)
  subject.product(action).map!(&RULES_NSFN)
end
mappings(kind, key) click to toggle source
# File lib/dry/ability/container.rb, line 38
def mappings(kind, key)
  F.collect_mappings(key, self, MAPPING_NSFN[kind], &:to_s)
end
resolve_with_mappings(action, subject) { |exception| ... } click to toggle source

@yieldparam exception

Yields block with an instance of +RuleNotDefault+ exception class
# File lib/dry/ability/container.rb, line 17
def resolve_with_mappings(action, subject)
  candidates = key_candidates(action, subject)
  result = []
  candidates.each do |key|
    next unless key?(key)
    result << resolve(key)
  end
  if result.blank?
    exception = RuleNotDefined.new(action: action, subject: subject, candidates: candidates)
    raise exception unless block_given?
    yield(exception)
  else
    result
  end
end