Class: Textus::Manifest::Policy
- Inherits:
-
Object
- Object
- Textus::Manifest::Policy
- Defined in:
- lib/textus/manifest/policy.rb
Overview
Authority over zones and roles derived from a Manifest::Data snapshot. Encapsulates the lookups previously living on Manifest itself (zone_writers, permission_for, role_kind, roles_with_kind). Derived / proposal-queue status is authoritative via the declared-kind family (declared_kind, derived_zone?, queue_zone?, queue_zone), not inferred from writers.
Instance Method Summary collapse
-
#declared_kind(zone_name) ⇒ Object
The kind declared on a zone in the manifest, or nil if undeclared.
-
#derived_zone?(zone_name) ⇒ Boolean
A zone is derived iff it declares kind: derived.
-
#initialize(data) ⇒ Policy
constructor
A new instance of Policy.
- #permission_for(zone_name) ⇒ Object
-
#propose_zone_for(role) ⇒ Object
The zone a proposer role writes proposals into: the single zone that declares kind: queue, when the role can write it.
-
#queue_zone ⇒ Object
The single zone declaring ‘kind: queue`, or nil.
-
#queue_zone?(zone_name) ⇒ Boolean
A zone is a proposal queue iff it declares kind: queue.
- #role_kind(name) ⇒ Object
- #role_mapping ⇒ Object
- #roles_with_kind(kind) ⇒ Object
- #zone_readers ⇒ Object
- #zone_writers(zone_name) ⇒ Object
Constructor Details
#initialize(data) ⇒ Policy
Returns a new instance of Policy.
10 11 12 |
# File 'lib/textus/manifest/policy.rb', line 10 def initialize(data) @data = data end |
Instance Method Details
#declared_kind(zone_name) ⇒ Object
The kind declared on a zone in the manifest, or nil if undeclared.
31 32 33 |
# File 'lib/textus/manifest/policy.rb', line 31 def declared_kind(zone_name) @data.declared_zone_kinds[zone_name] end |
#derived_zone?(zone_name) ⇒ Boolean
A zone is derived iff it declares kind: derived.
41 42 43 |
# File 'lib/textus/manifest/policy.rb', line 41 def derived_zone?(zone_name) declared_kind(zone_name) == :derived end |
#permission_for(zone_name) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/textus/manifest/policy.rb', line 22 def (zone_name) Textus::Domain::Permission.new( zone: zone_name, write_policy: zone_writers(zone_name), read_policy: @data.zone_readers[zone_name] || :all, ) end |
#propose_zone_for(role) ⇒ Object
The zone a proposer role writes proposals into: the single zone that declares kind: queue, when the role can write it. Returns nil if there is no queue zone or the role cannot write it.
65 66 67 68 69 70 71 72 |
# File 'lib/textus/manifest/policy.rb', line 65 def propose_zone_for(role) return nil if role.nil? q = queue_zone return nil unless q && zone_writers(q).include?(role) q end |
#queue_zone ⇒ Object
The single zone declaring ‘kind: queue`, or nil. Schema guarantees <=1.
36 37 38 |
# File 'lib/textus/manifest/policy.rb', line 36 def queue_zone @data.declared_zone_kinds.key(:queue) end |
#queue_zone?(zone_name) ⇒ Boolean
A zone is a proposal queue iff it declares kind: queue.
46 47 48 |
# File 'lib/textus/manifest/policy.rb', line 46 def queue_zone?(zone_name) declared_kind(zone_name) == :queue end |
#role_kind(name) ⇒ Object
54 55 56 |
# File 'lib/textus/manifest/policy.rb', line 54 def role_kind(name) @data.role_mapping[name] end |
#role_mapping ⇒ Object
50 51 52 |
# File 'lib/textus/manifest/policy.rb', line 50 def role_mapping @data.role_mapping end |
#roles_with_kind(kind) ⇒ Object
58 59 60 |
# File 'lib/textus/manifest/policy.rb', line 58 def roles_with_kind(kind) @data.role_mapping.each_with_object([]) { |(name, k), acc| acc << name if k == kind } end |
#zone_readers ⇒ Object
18 19 20 |
# File 'lib/textus/manifest/policy.rb', line 18 def zone_readers @data.zone_readers end |
#zone_writers(zone_name) ⇒ Object
14 15 16 |
# File 'lib/textus/manifest/policy.rb', line 14 def zone_writers(zone_name) @data.zones[zone_name] or raise UsageError.new("undeclared zone '#{zone_name}'") end |