1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

We don't need a support from ActiveSupport for this simple configuration storage

This commit is contained in:
Akira Matsuda 2017-06-29 17:35:50 +09:00
parent fddd5ea819
commit 9229dce33e

View file

@ -1,28 +1,40 @@
# frozen_string_literal: true
require 'active_support/configurable'
module Kaminari
# Configures global settings for Kaminari
# Kaminari.configure do |config|
# config.default_per_page = 10
# end
include ActiveSupport::Configurable
class << self
def configure
yield config
end
config.instance_eval do
self.default_per_page = 25
self.max_per_page = nil
self.window = 4
self.outer_window = 0
self.left = 0
self.right = 0
self.page_method_name = :page
self.param_name = :page
self.max_pages = nil
self.params_on_first_page = false
def config
@_config ||= Config.new
end
end
class Config
attr_accessor :default_per_page, :max_per_page, :window, :outer_window, :left, :right, :page_method_name, :max_pages, :params_on_first_page
attr_writer :param_name
def initialize
@default_per_page = 25
@max_per_page = nil
@window = 4
@outer_window = 0
@left = 0
@right = 0
@page_method_name = :page
@param_name = :page
@max_pages = nil
@params_on_first_page = false
end
# If param_name was given as a callable object, call it when returning
def param_name
self[:param_name].respond_to?(:call) ? self[:param_name].call : self[:param_name]
@param_name.respond_to?(:call) ? @param_name.call : @param_name
end
end
end