class Interage::ApplicationQuery

Constants

PER_PAGE

Attributes

relation[RW]

Public Instance Methods

all() click to toggle source
# File lib/interage/application_query.rb, line 9
def all
  includes.relation
end
between_dates(column, start_date, finish_date = nil) click to toggle source
# 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 = {}) click to toggle source
# File lib/interage/application_query.rb, line 13
def build(attributes = {})
  all.new(attributes)
end
by_id(id) click to toggle source
# File lib/interage/application_query.rb, line 46
def by_id(id)
  @relation = relation.where(id: id) if id.present?

  self
end
decorate() click to toggle source
# File lib/interage/application_query.rb, line 56
def decorate
  @relation = ActiveDecorator::Decorator.instance.decorate(relation)

  self
end
find(id) click to toggle source
# File lib/interage/application_query.rb, line 17
def find(id)
  all.find_by(id: id)
end
includes() click to toggle source
# File lib/interage/application_query.rb, line 52
def includes
  self
end
paginate(page = 1) click to toggle source
# File lib/interage/application_query.rb, line 21
def paginate(page = 1)
  all.page(page).per(PER_PAGE)
end
search_ilike_for(colums, term) click to toggle source
# 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

Protected Instance Methods

empty_relation() click to toggle source
# File lib/interage/application_query.rb, line 66
def empty_relation
  @relation = relation.none

  self
end