Class: Queries::Note::Filter
- Inherits:
-
Object
- Object
- Queries::Note::Filter
- Defined in:
- lib/queries/note/filter.rb
Instance Attribute Summary collapse
- #note_object_id ⇒ Array
- #note_object_type ⇒ Array
-
#object_global_id ⇒ Object
Returns the value of attribute object_global_id.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
- #text ⇒ Object
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #note_object_id_facet ⇒ Object
- #note_object_type_facet ⇒ Object
- #object_global_id_facet ⇒ Object
- #table ⇒ Object
- #text_facet ⇒ Object
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
22 23 24 25 26 27 28 |
# File 'lib/queries/note/filter.rb', line 22 def initialize(params) @text = params[:text] @note_object_type = params[:note_object_type] @note_object_id = params[:note_object_id] @object_global_id = params[:object_global_id] @project_id = params[:project_id] end |
Instance Attribute Details
#note_object_id ⇒ Array
16 17 18 |
# File 'lib/queries/note/filter.rb', line 16 def note_object_id @note_object_id end |
#note_object_type ⇒ Array
12 13 14 |
# File 'lib/queries/note/filter.rb', line 12 def note_object_type @note_object_type end |
#object_global_id ⇒ Object
Returns the value of attribute object_global_id.
18 19 20 |
# File 'lib/queries/note/filter.rb', line 18 def object_global_id @object_global_id end |
#project_id ⇒ Object
Returns the value of attribute project_id.
20 21 22 |
# File 'lib/queries/note/filter.rb', line 20 def project_id @project_id end |
#text ⇒ Object
8 9 10 |
# File 'lib/queries/note/filter.rb', line 8 def text @text end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/queries/note/filter.rb', line 82 def all q = nil if a = and_clauses q = ::Note.where(and_clauses) else q = ::Note.all end q = q.where(project_id: project_id) if !project_id.blank? q end |
#and_clauses ⇒ ActiveRecord::Relation
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/queries/note/filter.rb', line 66 def and_clauses clauses = [ text_facet, note_object_id_facet, note_object_type_facet, object_global_id_facet, ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#note_object_id_facet ⇒ Object
52 53 54 55 |
# File 'lib/queries/note/filter.rb', line 52 def note_object_id_facet return nil if note_object_id.empty? table[:note_object_id].eq_any(note_object_id) end |
#note_object_type_facet ⇒ Object
47 48 49 50 |
# File 'lib/queries/note/filter.rb', line 47 def note_object_type_facet return nil if note_object_type.empty? table[:note_object_type].eq_any(note_object_type) end |
#object_global_id_facet ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/queries/note/filter.rb', line 57 def object_global_id_facet return nil if object_global_id.nil? o = GlobalID::Locator.locate(object_global_id) k = o.class.base_class.name id = o.id table[:note_object_id].eq(o.id).and(table[:note_object_type].eq(k)) end |
#table ⇒ Object
38 39 40 |
# File 'lib/queries/note/filter.rb', line 38 def table ::Note.arel_table end |
#text_facet ⇒ Object
42 43 44 45 |
# File 'lib/queries/note/filter.rb', line 42 def text_facet return nil if text.blank? table[:text].matches('%' + text + '%') end |