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



53
54
55
56
57
# File 'lib/by_star/orm/active_record/by_star.rb', line 53

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

#previous(options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/by_star/orm/active_record/by_star.rb', line 47

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