Class: Textus::Manifest::Policy::Predicates::RawWriteOnce

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest/policy/predicates/raw_write_once.rb

Class Method Summary collapse

Class Method Details

.call(manifest:, actor:, action:, key:, schemas: nil, envelope: nil, extra: {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/textus/manifest/policy/predicates/raw_write_once.rb', line 6

def self.call(manifest:, actor:, action:, key:, schemas: nil, envelope: nil, extra: {})
  return { pass: true } if key.nil?

  path = manifest.resolver.resolve(key).path
  return { pass: true } unless File.exist?(path)

  { pass: false, error: Textus::Error.new(
    :raw_write_once,
    "raw entry '#{key}' already exists; " \
    "delete it first (`textus key-delete #{key}`), then re-ingest",
  ) }
rescue Textus::UnknownKey
  { pass: true }
end