Class: Hyrax::AbstractTypeRelation

Inherits:
ActiveFedora::Relation
  • Object
show all
Defined in:
app/search_builders/hyrax/abstract_type_relation.rb

Direct Known Subclasses

ExposedModelsRelation, WorkRelation

Defined Under Namespace

Classes: DummyModel

Instance Method Summary collapse

Constructor Details

#initialize(allowable_types: nil, **opts) ⇒ AbstractTypeRelation

Returns a new instance of AbstractTypeRelation.



4
5
6
7
# File 'app/search_builders/hyrax/abstract_type_relation.rb', line 4

def initialize(allowable_types: nil, **opts)
  @allowable_types = allowable_types
  super(DummyModel, opts)
end

Instance Method Details

#allowable_typesObject



9
10
11
12
# File 'app/search_builders/hyrax/abstract_type_relation.rb', line 9

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

#equivalent_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/search_builders/hyrax/abstract_type_relation.rb', line 14

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

#search_model_clauseObject



18
19
20
21
22
23
24
# File 'app/search_builders/hyrax/abstract_type_relation.rb', line 18

def search_model_clause
  clauses = allowable_types.map do |k|
    ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: k.to_s)
  end
  # empty array returns nil, AF finder method handles it properly, see hyrax issue #2844
  clauses.size <= 1 ? clauses.first : "(#{clauses.join(' OR ')})"
end