Sha256: 590e8d237ede15f26c39d25039036d014061ff3dc68f9aa7c41a2b5b22af27cb
Contents?: true
Size: 932 Bytes
Versions: 1
Compression:
Stored size: 932 Bytes
Contents
require File.dirname(__FILE__)+'/ranked-model/ranker' require File.dirname(__FILE__)+'/ranked-model/railtie' if defined?(Rails::Railtie) module RankedModel # Signed MEDIUMINT in MySQL # MAX_RANK_VALUE = 65534 def self.included base base.class_eval do cattr_accessor :rankers extend RankedModel::ClassMethods before_save :handle_ranking scope :rank, lambda { |name| order arel_table[ ranker(name.to_sym).column ] } end end private def handle_ranking self.class.rankers.each do |ranker| ranker.with(self).handle_ranking end end module ClassMethods def ranker name rankers.find do |ranker| ranker.name == name end end private def ranks *args self.rankers ||= [] ranker = RankedModel::Ranker.new(*args) self.rankers << ranker attr_accessor "#{ranker.name}_position" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ranked-model-0.0.1 | lib/ranked-model.rb |