Module: Textus::Manifest::Policy::Predicates
- Defined in:
- lib/textus/manifest/policy/predicates.rb,
lib/textus/manifest/policy/predicates/etag_match.rb,
lib/textus/manifest/policy/predicates/author_held.rb,
lib/textus/manifest/policy/predicates/fresh_within.rb,
lib/textus/manifest/policy/predicates/schema_valid.rb,
lib/textus/manifest/policy/predicates/raw_write_once.rb,
lib/textus/manifest/policy/predicates/target_is_canon.rb,
lib/textus/manifest/policy/predicates/lane_writable_by.rb,
lib/textus/manifest/policy/predicates/lane_deletable_by.rb,
lib/textus/manifest/policy/predicates/raw_lane_ingest_only.rb
Defined Under Namespace
Classes: AuthorHeld, EtagMatch, FreshWithin, LaneDeletableBy, LaneWritableBy, RawLaneIngestOnly, RawWriteOnce, SchemaValid, TargetIsCanon
Constant Summary
collapse
- FLOOR =
{
put: %w[lane_writable_by raw_lane_ingest_only],
key_delete: %w[lane_deletable_by],
key_mv: %w[lane_writable_by raw_lane_ingest_only],
accept: %w[author_held],
reject: %w[author_held],
propose: %w[lane_writable_by raw_lane_ingest_only],
key_mv_prefix: %w[lane_writable_by raw_lane_ingest_only],
key_delete_prefix: %w[lane_writable_by raw_lane_ingest_only],
ingest: %w[lane_writable_by raw_write_once],
}.freeze
- CLASSES =
{
"lane_writable_by" => "LaneWritableBy",
"author_held" => "AuthorHeld",
"target_is_canon" => "TargetIsCanon",
"etag_match" => "EtagMatch",
"schema_valid" => "SchemaValid",
"fresh_within" => "FreshWithin",
"raw_lane_ingest_only" => "RawLaneIngestOnly",
"raw_write_once" => "RawWriteOnce",
"lane_deletable_by" => "LaneDeletableBy",
}.freeze
Class Method Summary
collapse
Class Method Details
.by_name(name) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/textus/manifest/policy/predicates.rb', line 31
def by_name(name)
short = CLASSES.fetch(name.to_s) do
raise Textus::UsageError.new("unknown predicate '#{name}'")
end
const_get(short)
end
|
.evaluate(manifest:, action:, actor:, key:, schemas: nil, envelope: nil, extra: {}, rule_predicates: []) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/textus/manifest/policy/predicates.rb', line 38
def evaluate(manifest:, action:, actor:, key:, schemas: nil, envelope: nil, extra: {}, rule_predicates: [])
failures = []
(FLOOR.fetch(action, []) + rule_predicates).uniq.each do |pred_name|
result = by_name(pred_name).call(
manifest:, schemas:, actor:, action:, key:, envelope:, extra:,
)
next if result[:pass]
raise result[:error] if result[:error]
failures << [pred_name, result[:reason]]
end
raise Textus::GuardFailed.new(failures) unless failures.empty?
end
|