Class: Textus::Protocol::Manifest::Policy
- Inherits:
-
Object
- Object
- Textus::Protocol::Manifest::Policy
- Defined in:
- lib/textus/protocol/manifest/policy.rb,
lib/textus/protocol/manifest/policy/publish_target.rb
Defined Under Namespace
Classes: PublishTarget
Constant Summary collapse
- PROPOSALS_WRITERS =
%w[human agent].freeze
Instance Attribute Summary collapse
-
#entries ⇒ Object
writeonly
Sets the attribute entries.
Instance Method Summary collapse
- #actor_for(lane_name) ⇒ Object
- #allowed!(role:, lane:, key: nil) ⇒ Object
-
#allowed?(role:, lane:) ⇒ Boolean
── Authorization ──.
-
#derived_entry?(key) ⇒ Boolean
── Existing methods (unchanged) ──.
-
#initialize(data) ⇒ Policy
constructor
A new instance of Policy.
- #machine_lane ⇒ Object
- #propose_lane_for(role) ⇒ Object
- #proposer_role ⇒ Object
- #queue_lane ⇒ Object
- #queue_lane?(lane_name) ⇒ Boolean
- #writers_for(lane_name) ⇒ Object
Constructor Details
#initialize(data) ⇒ Policy
Returns a new instance of Policy.
7 8 9 10 |
# File 'lib/textus/protocol/manifest/policy.rb', line 7 def initialize(data) @data = data @entries = nil end |
Instance Attribute Details
#entries=(value) ⇒ Object (writeonly)
Sets the attribute entries
12 13 14 |
# File 'lib/textus/protocol/manifest/policy.rb', line 12 def entries=(value) @entries = value end |
Instance Method Details
#actor_for(lane_name) ⇒ Object
33 34 35 |
# File 'lib/textus/protocol/manifest/policy.rb', line 33 def actor_for(lane_name) writers_for(lane_name).first end |
#allowed!(role:, lane:, key: nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/textus/protocol/manifest/policy.rb', line 20 def allowed!(role:, lane:, key: nil) return true if allowed?(role:, lane:) raise Textus::WriteForbidden.new(key, lane, holders: writers_for(lane)) end |
#allowed?(role:, lane:) ⇒ Boolean
── Authorization ──
16 17 18 |
# File 'lib/textus/protocol/manifest/policy.rb', line 16 def allowed?(role:, lane:) writers_for(lane).map(&:to_sym).include?(role.to_sym) end |
#derived_entry?(key) ⇒ Boolean
── Existing methods (unchanged) ──
45 46 47 48 |
# File 'lib/textus/protocol/manifest/policy.rb', line 45 def derived_entry?(key) entry = Array(@entries).find { |e| e.key == key } entry && entry.lane == "artifacts" end |
#machine_lane ⇒ Object
54 55 56 |
# File 'lib/textus/protocol/manifest/policy.rb', line 54 def machine_lane "artifacts" end |
#propose_lane_for(role) ⇒ Object
62 63 64 65 |
# File 'lib/textus/protocol/manifest/policy.rb', line 62 def propose_lane_for(role) proposers = writers_for("proposals") proposers.include?(role) ? "scratchpad.proposals" : nil end |
#proposer_role ⇒ Object
37 38 39 40 41 |
# File 'lib/textus/protocol/manifest/policy.rb', line 37 def proposer_role proposers = writers_for("proposals") = writers_for("knowledge") (proposers - ).first || proposers.first end |
#queue_lane ⇒ Object
50 51 52 |
# File 'lib/textus/protocol/manifest/policy.rb', line 50 def queue_lane "scratchpad.proposals" end |
#queue_lane?(lane_name) ⇒ Boolean
58 59 60 |
# File 'lib/textus/protocol/manifest/policy.rb', line 58 def queue_lane?(lane_name) lane_name == "scratchpad" end |
#writers_for(lane_name) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/textus/protocol/manifest/policy.rb', line 26 def writers_for(lane_name) return PROPOSALS_WRITERS if lane_name == "proposals" lane_map = Textus::Protocol::V4::LANES[lane_name] lane_map ? Array(lane_map[:writers]) : [] end |