Module: Queries::Concerns::Empty

Extended by:
ActiveSupport::Concern
Included in:
Source::Filter
Defined in:
lib/queries/concerns/empty.rb

Overview

Helpers for queries that reference created/updated fields

!! You must have ‘#base_query` defined in the module to use this concern !! You must call set_empty_params in initialize()

TODO: Isolate code to a gem

Concern specs are in

spec/lib/queries/source/filter_spec.rb

Instance Method Summary collapse

Instance Method Details

#empty_fields_facetScope

Returns:

  • (Scope)


38
39
40
41
42
43
44
45
# File 'lib/queries/concerns/empty.rb', line 38

def empty_fields_facet
  return nil if empty.empty?
  a = base_query
  empty.each do |f|
    a = a.where(f => nil)
  end
  a
end

#not_empty_fields_facetObject



47
48
49
50
51
52
53
54
# File 'lib/queries/concerns/empty.rb', line 47

def not_empty_fields_facet
  return nil if not_empty.empty?
  a = base_query
  not_empty.each do |f|
    a = a.where.not(f => nil)
  end
  a
end

#set_empty_params(params) ⇒ Object



31
32
33
34
# File 'lib/queries/concerns/empty.rb', line 31

def set_empty_params(params)
  @empty = params[:empty]
  @not_empty = params[:not_empty]
end