lib/version.rb in versioned-0.1.0 vs lib/version.rb in versioned-0.2.0
- old
+ new
@@ -15,6 +15,22 @@
alias_attribute :version, :number
def <=>(other)
number <=> other.number
end
+
+ def previous
+ find_related(:first, :number => {:$lt => number}, :order => 'number.desc')
+ end
+
+ def next
+ find_related(:first, :number => {:$gt => number}, :order => 'number.asc')
+ end
+
+ protected
+
+ def find_related(*args)
+ options = args.extract_options!
+ params = options.merge(:versioned_id => versioned_id, :versioned_type => versioned_type)
+ self.class.find(args.first, params)
+ end
end