class OWS::ApplicationQuery
Constants
- DEFAULT_PER_PAGE
Attributes
relation[RW]
Public Class Methods
new()
click to toggle source
# File lib/ows/application_query.rb, line 10 def initialize init_relation end
Public Instance Methods
all()
click to toggle source
# File lib/ows/application_query.rb, line 18 def all includes.relation end
between_dates(column, start_date, finish_date = nil)
click to toggle source
# File lib/ows/application_query.rb, line 46 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/ows/application_query.rb, line 28 def build(attributes = {}) all.new(attributes) end
by_id(id)
click to toggle source
# File lib/ows/application_query.rb, line 57 def by_id(id) @relation = relation.where(id: id) if id.present? self end
decorate()
click to toggle source
# File lib/ows/application_query.rb, line 67 def decorate @relation = ActiveDecorator::Decorator.instance.decorate(relation) self end
distinct()
click to toggle source
# File lib/ows/application_query.rb, line 22 def distinct @relation = relation.distinct self end
includes()
click to toggle source
# File lib/ows/application_query.rb, line 63 def includes self end
init_relation()
click to toggle source
# File lib/ows/application_query.rb, line 14 def init_relation raise NotImplementedError, 'subclass did not define #init_relation' end
paginate(page = 1)
click to toggle source
# File lib/ows/application_query.rb, line 32 def paginate(page = 1) all.page(page).per(current_per_page) end
search_ilike_for(colums, term)
click to toggle source
# File lib/ows/application_query.rb, line 36 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
current_per_page()
click to toggle source
# File lib/ows/application_query.rb, line 83 def current_per_page DEFAULT_PER_PAGE end
empty_relation()
click to toggle source
# File lib/ows/application_query.rb, line 77 def empty_relation @relation = relation.none self end