Sha256: c5d14d891544c84d579b177f1db0e69d7a693fe5690935a51bf61f7470630ddb

Contents?: true

Size: 1.59 KB

Versions: 40

Compression:

Stored size: 1.59 KB

Contents

module CurationConcerns
  module FileSet
    module BelongsToWorks
      extend ActiveSupport::Concern

      included do
        before_destroy :remove_representative_relationship
      end

      def parents
        in_works
      end

      # 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)
      def parent
        parents.first
      end

      # Returns the id of 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)
      delegate :id, to: :parent, prefix: true

      # Files with sibling relationships
      # Returns all FileSets aggregated by any of the parent objects that
      # aggregate the current object
      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

      # If any parent objects are pointing at this object as their
      # representative, remove that pointer.
      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
    end
  end
end
\

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.7 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-2.0.0 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-2.0.0.rc2 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.6 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.5 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.4 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.3 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.2 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-2.0.0.rc1 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.1 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.0 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.7.0.beta1 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.6.3 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.6.2 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.6.1 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.6.0 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.5.0 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.4.0 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
curation_concerns-1.3.3 app/models/concerns/curation_concerns/file_set/belongs_to_works.rb