Class: Queries::Note::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/note/filter.rb

Overview

!! does not inherit from base query

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Filter) initialize(params)

Returns a new instance of Filter



16
17
18
19
# File 'lib/queries/note/filter.rb', line 16

def initialize(params)
  @text = params[:text]
  @options = params
end

Instance Attribute Details

- (Object) options

General annotator options handling happens directly on the params as passed through to the controller, keep them together here



11
12
13
# File 'lib/queries/note/filter.rb', line 11

def options
  @options
end

- (Object) text

Params specific to Note



14
15
16
# File 'lib/queries/note/filter.rb', line 14

def text
  @text
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


41
42
43
44
45
46
47
# File 'lib/queries/note/filter.rb', line 41

def all
  if a = and_clauses
    ::Note.where(and_clauses)
  else
    ::Note.none
  end
end

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/queries/note/filter.rb', line 22

def and_clauses
  clauses = [
    Queries::Annotator.annotator_params(options, ::Note),
    matching_text,
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

- (Arel::Node?) matching_text

Returns:

  • (Arel::Node, nil)


36
37
38
# File 'lib/queries/note/filter.rb', line 36

def matching_text
  text.blank? ? nil : table[:text].eq(text) 
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


50
51
52
# File 'lib/queries/note/filter.rb', line 50

def table
  ::Note.arel_table
end