Class: Queries::Tag::Filter

Inherits:
Object
  • Object
show all
Includes:
Concerns::Polymorphic
Defined in:
lib/queries/tag/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.



23
24
25
26
27
28
29
30
# File 'lib/queries/tag/filter.rb', line 23

def initialize(params)
  @keyword_id = [params[:keyword_id]].flatten.compact
  @tag_object_type = params[:tag_object_type]
  @tag_object_id = params[:tag_object_id]
  @object_global_id = params[:object_global_id]

  set_polymorphic_ids(params)
end

Instance Attribute Details

#keyword_idObject

Array, Integer



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

def keyword_id
  @keyword_id
end

#tag_object_idObject

Array, Integer



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

def tag_object_id
  @tag_object_id
end

#tag_object_typeObject

Array, Integer



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

def tag_object_type
  @tag_object_type
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


73
74
75
76
77
78
79
# File 'lib/queries/tag/filter.rb', line 73

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

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/queries/tag/filter.rb', line 41

def and_clauses
  clauses = [
    #  ::Queries::Annotator.annotator_params(options, ::Tag),
    matching_keyword_id,
    matching_polymorphic_ids,
    matching_tag_object_id,
    matching_tag_object_type,
  ].compact

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

#matching_keyword_idArel::Node?

Returns:

  • (Arel::Node, nil)


58
59
60
# File 'lib/queries/tag/filter.rb', line 58

def matching_keyword_id
  !keyword_id.empty? ? table[:keyword_id].eq_any(keyword_id)  : nil
end

#matching_tag_object_idArel::Node?

Returns:

  • (Arel::Node, nil)


63
64
65
# File 'lib/queries/tag/filter.rb', line 63

def matching_tag_object_id
  tag_object_id.empty? ? nil : table[:tag_object_id].eq_any(tag_object_id)
end

#matching_tag_object_typeArel::Node?

Returns:

  • (Arel::Node, nil)


68
69
70
# File 'lib/queries/tag/filter.rb', line 68

def matching_tag_object_type
  tag_object_type.empty? ? nil : table[:tag_object_type].eq_any(tag_object_type)
end

#tableArel::Table

Returns:

  • (Arel::Table)


82
83
84
# File 'lib/queries/tag/filter.rb', line 82

def table
  ::Tag.arel_table
end