Sha256: 9b51fdd1bfa1b930fbd7719a4ea4b1ccd0445e2c6b57a363a9911b38e01eede0

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Bulkrax
  module DynamicRecordLookup
    # Search entries, collections, and every available work type for a record that
    # has the provided identifier.
    #
    # @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier
    # @return [Work, Collection, nil] Work or Collection if found, otherwise nil
    def find_record(identifier)
      record = Entry.find_by(identifier: identifier)
      record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy
      if record.blank?
        available_work_types.each do |work_type|
          record ||= work_type.where(id: identifier).first # rubocop:disable Rails/FindBy
        end
      end

      record.is_a?(Entry) ? record.factory.find : record
    end

    # Check if the record is a Work
    def curation_concern?(record)
      available_work_types.include?(record.class)
    end

    private

    # @return [Array<Class>] list of work type classes
    def available_work_types
      # If running in a Hyku app, do not include disabled work types
      @available_work_types ||= if defined?(::Hyku)
                                  ::Site.instance.available_works.map(&:constantize)
                                else
                                  ::Hyrax.config.curation_concerns
                                end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bulkrax-3.0.0.beta3 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-3.0.0.beta2 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-3.0.0.beta1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.3.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.2.4 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.2.3 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.2.2 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.2.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.2.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.1.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-2.1.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb