Sha256: 1ad87f9e8f2a0bb4161735be3360dd9748c83f328fa8d7b6f704ee83468c07ee

Contents?: true

Size: 845 Bytes

Versions: 5

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module Hyrax
  class ValkyrieAbstractTypeRelation
    def initialize(allowable_types: nil, _opts: {})
      @allowable_types = allowable_types
    end

    def allowable_types
      @allowable_types.present? ||
        raise(NotImplementedException, "Implement allowable_types in a subclass")
    end

    def equivalent_class?(klass)
      allowable_types.include?(klass)
    end

    def count
      Hyrax.query_service.custom_queries.find_count_by(models: allowable_types)
    end

    def where(hash)
      Hyrax.query_service.find_references_by(resource: hash.values.first, property: hash.keys.first)
    end

    def ==(other)
      case other
      when Relation
        other.where_values == where_values
      when Array
        to_a == other
      end
    end

    delegate :inspect, to: :to_a
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/search_builders/hyrax/valkyrie_abstract_type_relation.rb
hyrax-5.0.0 app/search_builders/hyrax/valkyrie_abstract_type_relation.rb
hyrax-5.0.0.rc3 app/search_builders/hyrax/valkyrie_abstract_type_relation.rb
hyrax-5.0.0.rc2 app/search_builders/hyrax/valkyrie_abstract_type_relation.rb
hyrax-5.0.0.rc1 app/search_builders/hyrax/valkyrie_abstract_type_relation.rb