Class: GlobalRecordRepositoryLinkages

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/global_record_repository_linkages.rb

Instance Method Summary collapse

Constructor Details

#initialize(global_record_model, relationship) ⇒ GlobalRecordRepositoryLinkages

Returns a new instance of GlobalRecordRepositoryLinkages.



18
19
20
21
22
23
24
25
# File 'backend/app/model/global_record_repository_linkages.rb', line 18

def initialize(global_record_model, relationship)
  @global_record_model = global_record_model
  @relationship = @global_record_model.find_relationship(relationship)

  if @global_record_model.model_scope != :global
    raise "#{self} only works with global model types"
  end
end

Instance Method Details

#call(records) ⇒ Object

Return a hash like:

obj=""> => [#, #], ...



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'backend/app/model/global_record_repository_linkages.rb', line 31

def call(records)
  record_id_to_repo_ids = build_id_map(records)

  repositories = Repository.all.group_by(&:id)

  result = {}
  records.each do |record|
    result[record] = record_id_to_repo_ids
                     .fetch(record.id, [])
                     .map {|repo_ids| repositories.fetch(repo_ids)}
                     .flatten
  end

  result
end