Sha256: 48c1c094f1bdcdb638a323179742f83cdb9724c89c115c8643084d62dbda659b
Contents?: true
Size: 801 Bytes
Versions: 1
Compression:
Stored size: 801 Bytes
Contents
module ScopedTraversal module ModelAdditions def traverse_by(scope, options = {}) if options[:namespace] == true next_method_name = "next_#{scope}" previous_method_name = "previous_#{scope}" elsif options[:namespace] next_method_name = "next_#{options[:namespace]}" previous_method_name = "next_#{options[:namespace]}" else next_method_name = "next" previous_method_name = "previous" end define_method next_method_name do list = self.class.try(scope.to_sym).all list[list.index(self) + 1] end define_method previous_method_name do list = self.class.try(scope.to_sym).all list[list.index(self) - 1] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
scoped_traversal-0.1 | lib/scoped_traversal/model_additions.rb |