Sha256: 72b9d9b1ca29879830f9b74ca595d5e7903d30b4d879ed2c34a6c1d5d1c8e33b

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'kaminari/data_mapper/data_mapper_collection_methods'

module Kaminari
  module DataMapper
    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::DataMapper::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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kaminari-data_mapper-0.1.0 lib/kaminari/data_mapper/data_mapper_extension.rb