Class: Interage::ApplicationQuery
- Inherits:
-
Object
- Object
- Interage::ApplicationQuery
- Defined in:
- lib/interage/application_query.rb
Direct Known Subclasses
Constant Summary collapse
- PER_PAGE =
50
Instance Method Summary collapse
- #all ⇒ Object
- #between_dates(column, start_date, finish_date = nil) ⇒ Object
- #build(attributes = {}) ⇒ Object
- #by_id(id) ⇒ Object
- #decorate ⇒ Object
- #find(id) ⇒ Object
- #includes ⇒ Object
- #paginate(page = 1) ⇒ Object
- #search_ilike_for(colums, term) ⇒ Object
Instance Method Details
#all ⇒ Object
9 10 11 |
# File 'lib/interage/application_query.rb', line 9 def all includes.relation end |
#between_dates(column, start_date, finish_date = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/interage/application_query.rb', line 35 def between_dates(column, start_date, finish_date = nil) start_date = Date.current if start_date.blank? finish_date = start_date if finish_date.blank? range_date = start_date.to_date.beginning_of_day..finish_date.to_date.end_of_day @relation = relation.where(column => range_date) self end |
#build(attributes = {}) ⇒ Object
13 14 15 |
# File 'lib/interage/application_query.rb', line 13 def build(attributes = {}) all.new(attributes) end |
#by_id(id) ⇒ Object
46 47 48 49 50 |
# File 'lib/interage/application_query.rb', line 46 def by_id(id) @relation = relation.where(id: id) if id.present? self end |
#decorate ⇒ Object
56 57 58 59 60 |
# File 'lib/interage/application_query.rb', line 56 def decorate @relation = ActiveDecorator::Decorator.instance.decorate(relation) self end |
#find(id) ⇒ Object
17 18 19 |
# File 'lib/interage/application_query.rb', line 17 def find(id) all.find_by(id: id) end |
#includes ⇒ Object
52 53 54 |
# File 'lib/interage/application_query.rb', line 52 def includes self end |
#paginate(page = 1) ⇒ Object
21 22 23 |
# File 'lib/interage/application_query.rb', line 21 def paginate(page = 1) all.page(page).per(PER_PAGE) end |
#search_ilike_for(colums, term) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/interage/application_query.rb', line 25 def search_ilike_for(colums, term) return self unless term params = { t: "%#{term.to_s.downcase}%" } colums = colums.map { |colum| "unaccent(#{colum}) ILIKE unaccent(:t)" } @relation = relation.where(colums.join(' OR '), params) self end |