Class: Queries::Serial::Filter

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

Overview

!! does not inherit from base query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter



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

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

Instance Attribute Details

#nameObject

Params specific to Note



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

def name
  @name
end

#optionsObject

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/serial/filter.rb', line 11

def options
  @options
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


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

def all
  if a = and_clauses
    ::Serial.where(and_clauses.to_sql)
  else
    ::Serial.all
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


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

def and_clauses
  clauses = [
      matching_name,
  ].compact

  return nil if clauses.empty?

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

#matching_nameArel::Node?

Returns:

  • (Arel::Node, nil)


37
38
39
# File 'lib/queries/serial/filter.rb', line 37

def matching_name
  name.blank? ? nil : table[:name].eq(name)
end

#tableArel::Table

Returns:

  • (Arel::Table)


51
52
53
# File 'lib/queries/serial/filter.rb', line 51

def table
  ::Serial.arel_table
end