Class: Textus::Domain::Policy::Predicates::AuthorHeld

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/domain/policy/predicates/author_held.rb

Overview

Predicate: the acting role must hold the ‘author’ capability in the active manifest (ADR 0030 capability roles). Folds in the old Write::AuthorityGate so accept/reject and rules[].guard share one implementation. No bespoke #error — failures accumulate into GuardFailed (ADR 0031).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason.



13
14
15
# File 'lib/textus/domain/policy/predicates/author_held.rb', line 13

def reason
  @reason
end

Instance Method Details

#call(eval) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/textus/domain/policy/predicates/author_held.rb', line 17

def call(eval)
  holders = eval.manifest.policy.roles_with_capability("author")
  return true if holders.include?(eval.actor.to_s)

  @reason =
    if holders.empty?
      "no role holds the 'author' capability; #{eval.transition} is disabled"
    else
      "role '#{eval.actor}' lacks the 'author' capability (held by: #{holders.join(", ")})"
    end
  false
end

#nameObject



15
# File 'lib/textus/domain/policy/predicates/author_held.rb', line 15

def name = "author_held"