module Yap
Support for Active Record pagination. All options can be safely accessed by the user through url query parameters. To get the number of the last page call the last_page method with the same parameters as the pagination.
User.paginate # => Page 1 with default order and size. User.paginate(params) # => Passing parameters in controller. User.paginate( page: 1, per_page: 10, sort: :id, direction: :asc ) # => Invocation with custom options. User.last_page # => Last page as a number for defaults User.last_page(params) # => Last page for given params. Works the same way as paginate.
@see Filterable
Filter
results by attributes.
ActiveRecords can be filtered by their attributes if either Yap
or Filterable
is included into the model. Filters can be applied through the filter or paginate scope. Multiple filters for the same attribute can be separated by comma, negative filters have a leading exclamation mark (!) and 'null' will be translated to the NULL value.
User.filtered('gender' => 'f') # => All female users. User.filtered( 'team_id' => '1,2', 'gender' => 'm' ) # => All males of teams 1 and 2. User.filtered('team_id' => '!null') # => All users with any team. User.paginate(params) # => Passing parameters in controller (http://localhost/users?filter[gender]=f) User.paginate( page: 1, filter: { 'team' => 'null' } ) # => Combining filter and pagination.
Constants
- DEFAULTS
- VERSION
Public Class Methods
configuration()
click to toggle source
# File lib/yap.rb, line 39 def self.configuration DEFAULTS.dup end
configure() { |DEFAULTS| ... }
click to toggle source
# File lib/yap.rb, line 33 def self.configure raise ArgumentError, 'No block given.' unless block_given? yield(DEFAULTS) end