Class: Textus::Protocol::Manifest::Policy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute entries to.



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 ──

Returns:

  • (Boolean)


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) ──

Returns:

  • (Boolean)


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_laneObject



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_roleObject



37
38
39
40
41
# File 'lib/textus/protocol/manifest/policy.rb', line 37

def proposer_role
  proposers = writers_for("proposals")
  authors = writers_for("knowledge")
  (proposers - authors).first || proposers.first
end

#queue_laneObject



50
51
52
# File 'lib/textus/protocol/manifest/policy.rb', line 50

def queue_lane
  "scratchpad.proposals"
end

#queue_lane?(lane_name) ⇒ Boolean

Returns:

  • (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