Class: Hyrax::ValkyrieAbstractTypeRelation

Inherits:
Object
  • Object
show all
Defined in:
app/search_builders/hyrax/valkyrie_abstract_type_relation.rb

Direct Known Subclasses

ValkyrieWorkRelation

Instance Method Summary collapse

Constructor Details

#initialize(allowable_types: nil, _opts: {}) ⇒ ValkyrieAbstractTypeRelation

Returns a new instance of ValkyrieAbstractTypeRelation.



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

def initialize(allowable_types: nil, _opts: {})
  @allowable_types = allowable_types
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'app/search_builders/hyrax/valkyrie_abstract_type_relation.rb', line 31

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

#allowable_typesObject



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

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

#countObject



18
19
20
# File 'app/search_builders/hyrax/valkyrie_abstract_type_relation.rb', line 18

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

#equivalent_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#where(hash_or_string) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/search_builders/hyrax/valkyrie_abstract_type_relation.rb', line 22

def where(hash_or_string)
  case hash_or_string
  when String
    Hyrax::SolrService.query(hash_or_string)
  else
    Hyrax.query_service.find_references_by(resource: hash_or_string.values.first, property: hash_or_string.keys.first)
  end
end