Module: Queries::Concerns::Confidences

Overview

Query on confidence attributes

For filter queries: !! requires ‘set_confidences_params` be called in initialize()

Tested on spec/lib/queries/otu/filter_spec.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#boolean_param, #integer_param

Class Method Details

.merge_clausesObject



85
86
87
88
89
90
91
# File 'lib/queries/concerns/confidences.rb', line 85

def self.merge_clauses
  [
    :confidences_facet,
    :without_confidence_level_id_facet,
    :confidence_level_id_facet,
  ]
end

.paramsObject



10
11
12
13
14
15
16
17
18
# File 'lib/queries/concerns/confidences.rb', line 10

def self.params
  [
    :confidences,
    :without_confidence_level_id,
    :confidence_level_id, 
    confidence_level_id: [],
    without_confidence_level_id: []
  ]
end

Instance Method Details

#confidence_level_id_facetObject



60
61
62
63
# File 'lib/queries/concerns/confidences.rb', line 60

def confidence_level_id_facet
  return nil if confidence_level_id.empty?
  referenced_klass.joins(:confidences).where(confidences: {confidence_level_id: confidence_level_id})
end

#confidence_tableArel::Table

Returns:

  • (Arel::Table)


56
57
58
# File 'lib/queries/concerns/confidences.rb', line 56

def confidence_table
  ::Confidence.arel_table
end

#confidences_facetObject



76
77
78
79
80
81
82
83
# File 'lib/queries/concerns/confidences.rb', line 76

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

#set_confidences_params(params) ⇒ Object



49
50
51
52
53
# File 'lib/queries/concerns/confidences.rb', line 49

def set_confidences_params(params)
  @confidence_level_id = params[:confidence_level_id]
  @without_confidence_level_id = params[:without_confidence_level_id]
  @confidences = boolean_param(params, :confidences)
end

#without_confidence_level_id_facetObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/queries/concerns/confidences.rb', line 65

def without_confidence_level_id_facet
  return nil if without_confidence_level_id.empty?
  not_these = referenced_klass.left_joins(:confidences).where(confidences: {confidence_level_id: without_confidence_level_id})

  s = referenced_klass.with(not_these:)
    .joins("LEFT JOIN not_these AS not_these1 ON not_these1.id = #{table.name}.id")
    .where('not_these1.id IS NULL').to_sql

  referenced_klass.from("(#{s}) as #{table.name}")
end