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

- (Filter) initialize(params)

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

- (Object) confidence_level_id

Array, Integer



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

def confidence_level_id
  @confidence_level_id
end

- (Object) confidence_object_type

Array, Integer



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

def confidence_object_type
  @confidence_object_type
end

- (Object) object_global_id

Array, Integer



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

def object_global_id
  @object_global_id
end

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

def options
  @options
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


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

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

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

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

- (Arel::Node?) matching_confidence_level_id

Returns:

  • (Arel::Node, nil)


65
66
67
# File 'lib/queries/confidence/filter.rb', line 65

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

- (Arel::Node?) matching_confidence_object_type

Returns:

  • (Arel::Node, nil)


70
71
72
# File 'lib/queries/confidence/filter.rb', line 70

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

- (Arel::Node?) matching_object

TODO: Dry

Returns:

  • (Arel::Node, nil)


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

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

- (ActiveRecord object?) object_for

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


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

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


84
85
86
# File 'lib/queries/confidence/filter.rb', line 84

def table
  ::Confidence.arel_table
end