Coder Social home page Coder Social logo

jinrai's Introduction

Jinrai

Jinrai is a awesome cursor based paginator

Usage

# config/initializers/jinrai.rb

Jinrai.configure do |config|
  config.default_cursor_per = 20 #=> User.cursor.count == 20
  config.default_cursor_format = :id, :name #=> cursor format will be "#{user.id}_#{user.name}"
  config.default_cursor_sort_order = :desc
end
# app/model/user.rb

class User < ApplicationRecord
  cursor_per 100
  cursor_format :name, :age
  cursor_sort_order :asc # default: :desc
end

User.cursor.count #=> 100
User.cursor.since_format #=> generate cursor fomatted "#{user.name}_#{user.age}"
User.cursor #=> get latest 20 records.
User.cursor.count #=> 20

.cursor has two arguments, till and since, and by passing them we can get record collection of arbitrary interval.

since_cursor = User.cursor.till_cursor
User.cursor(since: since_cursor) # return records older than the record pointed by the cursor

till_cursor = User.cursor.since_cursor
User.cursor(till: till_cursor) # return records newer than the record pointed by the cursor

User.cursor(since: since_cursor, till: till_cursor) # return records newer than the record pointed by the since cursor and older than the record pointed by the till cursor.

Get cursor by calling since_cursor or till_cursor.

users = User.cursor
users.since_cursor # this cursor points first record of User collection
users.till_cursor # this cursor points last record of User collection

Installation

Add this line to your application's Gemfile:

gem 'jinrai'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jinrai

Contributing

  1. Fork then clone this repo:
git clone [email protected]:YOUR_USERNAME/jinrai.git
  1. Create database
$ mysql --host 127.0.0.1  -uroot -e "create database jinrai_test"
  1. setup dependencies via bundler:
bundle install
  1. Make sure the spec pass:
bundle exec rspec
  1. Make your change, and write spec, make sure test pass:
bundle exec rspec
  1. write a good commit message, push to your fork, then submit PullRequest.

License

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

jinrai's People

Contributors

a-tommyyy avatar mashvalue1 avatar yshimada0330 avatar knzwats avatar mc-chinju avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.