No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 2 commits ahead of jiikko:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
multi_model_paginator.gemspec

README.md

MultiModelPaginator

  • 複数のモデルでページネーションを行うgemです
  • 追加されたクエリ毎のカウントをとっていい感じにページネーションします

Dependencies

  • ActiveRecord

Installation

Add this line to your application's Gemfile:

gem 'multi_model_paginator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multi_model_paginator

Usage

Account.count # => 3
Item.count    # => 5

paginator = MultiModelPaginator.new(per: 2, page: 0)
paginator.add(Account.all)
paginator.add(Item.all)
# D, [2018-05-29T22:28:55.104813 #7189] DEBUG -- :   CACHE  (0.0ms)  SELECT COUNT(*) FROM "accounts"
# D, [2018-05-29T22:28:55.105422 #7189] DEBUG -- :   CACHE Account Load (0.0ms)  SELECT  "accounts".* FROM "accounts" LIMIT 2 OFFSET 0
paginator.result.map(&:class).map(&:to_s) # =>["Account", "Account"]

paginator = MultiModelPaginator.new(per: 2, page: 1)
paginator.add(Account.all)
paginator.add(Item.all)
# D, [2018-05-29T22:29:37.069335 #7189] DEBUG -- :   CACHE  (0.0ms)  SELECT COUNT(*) FROM "accounts"
# D, [2018-05-29T22:29:37.069765 #7189] DEBUG -- :   CACHE Account Load (0.0ms)  SELECT  "accounts".* FROM "accounts" LIMIT 2 OFFSET 2
# D, [2018-05-29T22:29:37.070255 #7189] DEBUG -- :   CACHE  (0.0ms)  SELECT COUNT(*) FROM "items"
# D, [2018-05-29T22:29:37.070821 #7189] DEBUG -- :   CACHE Item Load (0.0ms)  SELECT  "items".* FROM "items" LIMIT 2 OFFSET 0
paginator.result.map(&:class).map(&:to_s) # => ["Account", "Item"]

License

The gem is available as open source under the terms of the MIT License.