Module: Repertoire::Faceting::Facets::AbstractFacet

Included in:
BasicFacet, NestedFacet
Defined in:
lib/repertoire-faceting/facets/abstract_facet.rb

Overview

Abstract interface all facet implementations must fulfil. At minimum, implementors should define self.claim?(), signature(), and drill() to create a new kind of facet.

For indexing support, implement create_index(), refresh_index(), and drop_index(). Detect the index’s presence in signature() and drill(), and act accordingly.

N.B. Facet instances can assume they have been mixed in with an ActiveRecord::Relation and

Repertoire::Faceting::Model (see the mixin() method below). Think of them as scoped
relations that identify an attribute of the model dataset.

See BasicFacet and NestedFacet for examples of facet implementations.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#facet_nameObject

Returns the value of attribute facet_name.



21
22
23
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 21

def facet_name
  @facet_name
end

Class Method Details

.claim?(relation) ⇒ Boolean

Return true if this facet implementation can index this ActiveRecord relation. If multiple implementations claim a facet, the one that is laoded last wins.

Returns:

  • (Boolean)


25
26
27
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 25

def self.claim?(relation)
  raise "Please implement claim? for your facet"
end

Instance Method Details

#create_indexObject

Create this facet’s index table, or raise an exception if indexing not supported. Signatures should be constructed from the column returned by faceting_id().



44
45
46
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 44

def create_index
  raise "Facet #{facet_name} does not support indexing"
end

#drill(state) ⇒ Object

Return an arel expression for (state, signature) pairs from which one can refine the current state of this facet (ignoring all others). Signatures should be constructed from the column returned by faceting_id().



38
39
40
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 38

def drill(state)
  raise "Please implement drill for your facet"
end

#drop_indexObject

Drop this facet’s index, or raise an exception if it is not indexed



55
56
57
58
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 55

def drop_index
  raise "Facet #{facet_name} is not indexed" unless facet_indexed?
  connection.drop_materialized_view(facet_index_name)
end

#facet_indexed?Boolean

Returns true if the facet’s index table exists

Returns:

  • (Boolean)


61
62
63
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 61

def facet_indexed?
  indexed_facets.map(&:to_sym).include?(facet_name)
end

#refresh_indexObject

Refresh this facet’s index, or raise an exception if it is not indexed



49
50
51
52
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 49

def refresh_index
  raise "Facet #{facet_name} is not indexed" unless facet_indexed?
  connection.refresh_materialized_view(facet_index_name)
end

#signature(state) ⇒ Object

Return an arel expression for the signature of all models matching the given current refinement state for this facet (and ignoring all others). Signatures should be constructed from the column returned by faceting_id().



32
33
34
# File 'lib/repertoire-faceting/facets/abstract_facet.rb', line 32

def signature(state)
  raise "Please implement signature for your facet"
end