Class: Queries::Confidence::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/confidence/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



19
20
21
22
23
24
# File 'lib/queries/confidence/filter.rb', line 19

def initialize(params)
  @confidence_level_id = [params[:confidence_level_id]].flatten.compact
  @object_global_id = params[:object_global_id]
  @confidence_object_type = params[:confidence_object_type]
  @options = params
end

Instance Attribute Details

#confidence_level_idObject

Array, Integer



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

def confidence_level_id
  @confidence_level_id
end

#confidence_object_typeObject

Array, Integer



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

def confidence_object_type
  @confidence_object_type
end

#object_global_idObject

Array, Integer



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

def object_global_id
  @object_global_id
end

#optionsObject

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



13
14
15
# File 'lib/queries/confidence/filter.rb', line 13

def options
  @options
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


77
78
79
80
81
82
83
# File 'lib/queries/confidence/filter.rb', line 77

def all
  if a = and_clauses
    ::Confidence.where(and_clauses).distinct
  else
    ::Confidence.all
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/queries/confidence/filter.rb', line 27

def and_clauses
  clauses = [
    ::Queries::Annotator.annotator_params(options, ::Confidence),
    matching_confidence_level_id,
    matching_confidence_object_type,
    matching_object,
  ].compact

  return nil if clauses.empty? 
  
  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

#matching_confidence_level_idArel::Node?

Returns:

  • (Arel::Node, nil)


67
68
69
# File 'lib/queries/confidence/filter.rb', line 67

def matching_confidence_level_id
  !confidence_level_id.blank? ? table[:confidence_level_id].eq_any(confidence_level_id)  : nil
end

#matching_confidence_object_typeArel::Node?

Returns:

  • (Arel::Node, nil)


72
73
74
# File 'lib/queries/confidence/filter.rb', line 72

def matching_confidence_object_type
  !confidence_object_type.blank? ? table[:confidence_object_type].eq(confidence_object_type)  : nil
end

#matching_objectArel::Node?

TODO: Dry

Returns:

  • (Arel::Node, nil)


56
57
58
59
60
61
62
63
64
# File 'lib/queries/confidence/filter.rb', line 56

def matching_object
  if o = object_for
    table["confidence_object_id"].eq(o.id).and(
        table["confidence_object_type"].eq(o.metamorphosize.class.name)
    )
  else
    nil
  end
end

#object_forActiveRecord object?

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


46
47
48
49
50
51
52
# File 'lib/queries/confidence/filter.rb', line 46

def object_for
  if o = GlobalID::Locator.locate(object_global_id)
    o
  else
    nil
  end
end

#tableArel::Table

Returns:

  • (Arel::Table)


86
87
88
# File 'lib/queries/confidence/filter.rb', line 86

def table
  ::Confidence.arel_table
end