Class: Karst::Access::PopulationRevocation

Inherits:
Object
  • Object
show all
Defined in:
lib/karst/access/population_revocation.rb

Overview

Removes one exact, already-stored approval while preserving every other entry. Submitted values can never add or alter an approval.

Constant Summary collapse

Result =
Value.define(:record, :revoked)
SEPARATOR =
"::"

Instance Method Summary collapse

Constructor Details

#initialize(submitted:, record: PopulationApprovals.load) ⇒ PopulationRevocation

Returns a new instance of PopulationRevocation.



14
15
16
17
# File 'lib/karst/access/population_revocation.rb', line 14

def initialize(submitted:, record: PopulationApprovals.load)
  @submitted = .to_s
  @record = record
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
# File 'lib/karst/access/population_revocation.rb', line 19

def call
  entry = @record.entries.find { |candidate| key(candidate) == @submitted }
  return Result.new(record: @record, revoked: false) unless entry

  record = PopulationApprovals.replace(@record.entries - [entry])
  Result.new(record: record, revoked: record.error.nil?)
end