Module: CurationConcerns::FileSet::BelongsToWorks

Extended by:
ActiveSupport::Concern
Included in:
CurationConcerns::FileSetBehavior
Defined in:
app/models/concerns/curation_concerns/file_set/belongs_to_works.rb

Instance Method Summary collapse

Instance Method Details

#parentObject

Returns the first parent object This is a hack to handle things like FileSets inheriting access controls from their parent. (see CurationConcerns::ParentContainer in app/controllers/concerns/curation_concers/parent_container.rb)



16
17
18
# File 'app/models/concerns/curation_concerns/file_set/belongs_to_works.rb', line 16

def parent
  parents.first
end

#parentsObject



10
11
12
# File 'app/models/concerns/curation_concerns/file_set/belongs_to_works.rb', line 10

def parents
  in_works
end

Files with sibling relationships Returns all FileSets aggregated by any of the parent objects that aggregate the current object



27
28
29
30
31
32
33
34
35
# File 'app/models/concerns/curation_concerns/file_set/belongs_to_works.rb', line 27

def related_files
  parent_objects = parents
  return [] if parent_objects.empty?
  parent_objects.flat_map do |work|
    work.file_sets.select do |file_set|
      file_set.id != id
    end
  end
end

#remove_representative_relationshipObject

If any parent objects are pointing at this object as their representative, remove that pointer.



39
40
41
42
43
44
45
# File 'app/models/concerns/curation_concerns/file_set/belongs_to_works.rb', line 39

def remove_representative_relationship
  parent_objects = parents
  return if parent_objects.empty?
  parent_objects.each do |work|
    work.update(representative_id: nil) if work.representative_id == id
  end
end