From 9229dce33e5dcdd6fdb200356c06ee92e6bfef2d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 29 Jun 2017 17:35:50 +0900 Subject: [PATCH] We don't need a support from ActiveSupport for this simple configuration storage --- kaminari-core/lib/kaminari/config.rb | 40 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/kaminari-core/lib/kaminari/config.rb b/kaminari-core/lib/kaminari/config.rb index 3a8b613..45a47c4 100644 --- a/kaminari-core/lib/kaminari/config.rb +++ b/kaminari-core/lib/kaminari/config.rb @@ -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