cirandas.net

ref: master

app/models/posts_limit.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
module PostsLimit
  module ClassMethods
    def posts_per_page_limit
      15
    end

    def posts_per_page_options
      [5, 10, 15]
    end
  end

  def self.included(klass)
    klass.send(:extend, PostsLimit::ClassMethods)
    klass.class_eval do
      def posts_per_page_with_limit
        [self.class.posts_per_page_limit, posts_per_page_without_limit].min
      end
      alias_method_chain :posts_per_page, :limit
    end
  end
end