Module: Queries::Concerns::Notes

Overview

Helpers and facets for queries that reference Notes.

Test coverage is currently in spec/lib/queries/collection_object/filter_spec.rb.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.merge_clausesObject



42
43
44
45
46
47
# File 'lib/queries/concerns/notes.rb', line 42

def self.merge_clauses
  [
    :note_text_facet,
    :notes_facet
  ]
end

.paramsObject



9
10
11
12
13
14
15
# File 'lib/queries/concerns/notes.rb', line 9

def self.params
  [
    :note_exact,
    :note_text,
    :notes
  ]
end

Instance Method Details

#note_tableArel::Table

Returns:

  • (Arel::Table)


38
39
40
# File 'lib/queries/concerns/notes.rb', line 38

def note_table
  ::Note.arel_table
end

#note_text_facetObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/queries/concerns/notes.rb', line 49

def note_text_facet
  return nil if note_text.blank?

  if note_exact
    referenced_klass.joins(:notes).where(note_table[:text].eq(note_text))
  else
    referenced_klass.joins(:notes).where(
      note_table[:text].matches('%' + note_text + '%')
    )
  end
end

#notes_facetObject



61
62
63
64
65
66
67
68
# File 'lib/queries/concerns/notes.rb', line 61

def notes_facet
  return nil if notes.nil?
  if notes
    referenced_klass.joins(:notes).distinct
  else
    referenced_klass.where.missing(:notes)
  end
end

#set_notes_params(params) ⇒ Object



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

def set_notes_params(params)
  @note_exact = params[:note_exact]
  @note_text = params[:note_text]
  @notes = boolean_param(params, :notes)
end