Class: Karst::Access::PopulationApproval

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

Overview

Adds explicitly selected candidates from one current discovery pass to the local approval record. Submitted values are treated only as keys: the Entry objects written below always come from discovery itself.

Constant Summary collapse

Result =
Value.define(:record, :error) do
  def saved?
    error.nil? && record.error.nil?
  end
end
SEPARATOR =
"::"

Instance Method Summary collapse

Constructor Details

#initialize(discovery:, principal_sources:, submitted:, record: PopulationApprovals.load) ⇒ PopulationApproval

Returns a new instance of PopulationApproval.



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

def initialize(discovery:, principal_sources:, submitted:, record: PopulationApprovals.load)
  @discovery = discovery
  @principal_sources = principal_sources
  @submitted = Array().map(&:to_s)
  @record = record
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/karst/access/population_approval.rb', line 26

def call
  selected = selected_candidates
  return rejected("Select at least one current candidate population.") if @submitted.empty?
  return rejected("A submitted population is no longer available for this principal source.") unless selected

  entries = @record.entries + selected.map do |candidate|
    PopulationApprovals::Entry.new(model_name: candidate.model_name,
                                   method_name: candidate.method_name.to_s)
  end
  record = PopulationApprovals.replace(entries)
  Result.new(record: record, error: record.error)
end