Module: Kaminari::MandatoryOrdering::ActiveRecordModelExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/kaminari/mandatory_ordering/active_record_model_extension.rb

Class Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kaminari/mandatory_ordering/active_record_model_extension.rb', line 6

def self.prepended(klass)
  return unless Kaminari.config.mandatory_ordering

  original = klass.method(Kaminari.config.page_method_name)

  klass.define_singleton_method(Kaminari.config.page_method_name) do |number|
    if all.values.fetch(:order, []).none?
      raise Kaminari::MandatoryOrdering::Error
    else
      # TODO: Find out why calling `super` fails to find the previously defined method.
      original.call(number)
    end
  end
end