Module: ByStar::ActiveRecord

Extended by:
ActiveSupport::Concern
Defined in:
lib/by_star/orm/active_record/by_star.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#next(options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/by_star/orm/active_record/by_star.rb', line 63

def next(options={})
  field = self.class.by_star_start_field
  value = self.send(field.split(".").last)
  self.class.by_star_scope(options.merge(scope_args: self)).where("#{field} > ?", value).reorder("#{field} ASC").first
end

#previous(options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/by_star/orm/active_record/by_star.rb', line 57

def previous(options={})
  field = self.class.by_star_start_field
  value = self.send(field.split(".").last)
  self.class.by_star_scope(options.merge(scope_args: self)).where("#{field} < ?", value).reorder("#{field} DESC").first
end