Class: ModelFact::Helpers::FilterBuilder
- Inherits:
-
Object
- Object
- ModelFact::Helpers::FilterBuilder
- Defined in:
- lib/model_fact/helpers/filter_builder.rb
Overview
based on sql?
Instance Method Summary collapse
- #and(condHash = {}, opts = {}) ⇒ Object (also: #filter)
- #bottom(cnt = 1, opts = {}) ⇒ Object (also: #last)
-
#count ⇒ Object
def sub_list_items(fromIndx, len, opts = {}) modifier << { sub_index: { from: fromIndx, length: len } } self end.
- #go_to_page(pageNo) ⇒ Object
-
#initialize ⇒ FilterBuilder
constructor
A new instance of FilterBuilder.
- #is_return_count? ⇒ Boolean
- #main_cond ⇒ Object
- #modifier ⇒ Object
- #or(condHash = {}, opts = {}) ⇒ Object
- #sort(field, type = :asc) ⇒ Object (also: #order)
- #top(cnt = 1, opts = {}) ⇒ Object (also: #first)
Constructor Details
#initialize ⇒ FilterBuilder
Returns a new instance of FilterBuilder.
9 10 11 12 13 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 9 def initialize @mainCond = [] @modifier = [] @_return_count = false end |
Instance Method Details
#and(condHash = {}, opts = {}) ⇒ Object Also known as: filter
15 16 17 18 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 15 def and(condHash = {}, opts = {}) main_cond << { and: condHash } self end |
#bottom(cnt = 1, opts = {}) ⇒ Object Also known as: last
32 33 34 35 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 32 def bottom(cnt = 1, opts = {}) modifier << { last: cnt } self end |
#count ⇒ Object
def sub_list_items(fromIndx, len, opts = {})
modifier << { sub_index: { from: fromIndx, length: len } }
self
end
43 44 45 46 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 43 def count @_return_count = true self end |
#go_to_page(pageNo) ⇒ Object
52 53 54 55 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 52 def go_to_page(pageNo) modifier << { page: pageNo } self end |
#is_return_count? ⇒ Boolean
48 49 50 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 48 def is_return_count? @_return_count == true end |
#main_cond ⇒ Object
63 64 65 66 67 68 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 63 def main_cond if @_main_cond.nil? @_main_cond = [] end @_main_cond end |
#modifier ⇒ Object
70 71 72 73 74 75 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 70 def modifier if @_modifier.nil? @_modifier = [] end @_modifier end |
#or(condHash = {}, opts = {}) ⇒ Object
21 22 23 24 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 21 def or(condHash = {}, opts = {}) main_cond << { or: condHash } self end |
#sort(field, type = :asc) ⇒ Object Also known as: order
57 58 59 60 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 57 def sort(field, type = :asc) modifier << { sort: { field => type } } self end |
#top(cnt = 1, opts = {}) ⇒ Object Also known as: first
26 27 28 29 |
# File 'lib/model_fact/helpers/filter_builder.rb', line 26 def top(cnt = 1, opts = {}) modifier << { first: cnt } self end |