Sha256: e245019073e81dd6d35dc1673eb644c6ad0de101c5d17ae1b05456db36d8d9f2

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

require 'kaminari/models/data_mapper_collection_methods'

module Kaminari
  module DataMapperExtension
    module Paginatable
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{Kaminari.config.page_method_name}(num = 1)
          model = self
          model = self.model if self.is_a? DataMapper::Collection
          num = [num.to_i, 1].max - 1
          all(:limit => model.default_per_page, :offset => model.default_per_page * num).extend Paginating
        end
      RUBY
    end

    module Paginating
      include Kaminari::PageScopeMethods

      def all(options={})
        super.extend Paginating
      end

      def per(num)
        super.extend Paginating
      end
    end

    module Collection
      extend ActiveSupport::Concern
      included do
        include Kaminari::DataMapperCollectionMethods
        include Paginatable

        delegate :default_per_page, :max_per_page, :max_pages, :to => :model
      end
    end

    module Model
      include Kaminari::ConfigurationMethods::ClassMethods
      include Paginatable

      def limit(val)
        all(:limit => val)
      end

      def offset(val)
        all(:offset => val)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/kaminari-0.17.0/lib/kaminari/models/data_mapper_extension.rb
kaminari-0.17.0 lib/kaminari/models/data_mapper_extension.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/kaminari-0.16.3/lib/kaminari/models/data_mapper_extension.rb
kaminari-0.16.3 lib/kaminari/models/data_mapper_extension.rb
kaminari-0.16.2 lib/kaminari/models/data_mapper_extension.rb
kaminari-0.16.1 lib/kaminari/models/data_mapper_extension.rb
kaminari-0.16.0 lib/kaminari/models/data_mapper_extension.rb
kaminari-0.15.1 lib/kaminari/models/data_mapper_extension.rb
kaminari-0.15.0 lib/kaminari/models/data_mapper_extension.rb