Module: Repertoire::Faceting::Relation::Calculations

Included in:
ActiveRecord::Relation
Defined in:
lib/repertoire-faceting/relation/calculations.rb

Instance Method Summary collapse

Instance Method Details

#count(name = nil, options = {}) ⇒ Object

Construct and execute a count over the specified facet.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/repertoire-faceting/relation/calculations.rb', line 9

def count(name = nil, options = {})
  if name.present? && @klass.respond_to?(:facet?) && @klass.facet?(name)
    name       = name.to_sym
    parent     = @klass.facets[name]
    facet      = parent.merge(self)
    state      = refine_value[name] || []
    signatures = facet.drill(state)

    facet.minimum_value = self.minimum_value || parent.minimum_value
    facet.nils_value    = self.nils_value    || parent.nils_value

    connection.population(facet, masks, signatures)
  else
    super
  end
end