class A2::Paginated
Public Class Methods
new(name, opts = {})
click to toggle source
Calls superclass method
A2::Filtered::new
# File lib/a2/mixins/paginated.rb, line 3 def initialize(name, opts = {}) disable_sort_opts = opts.delete(:disable_sort_opts) || false super(name, opts) @opt[:order] = 'ASC' unless disable_sort_opts options.on('-o', '--order ORDER', 'Return the results in ascending or descending order. Default is "ASC".') do |order| @opt[:order] = order end unless disable_sort_opts options.on('-s', '--sort SORT', 'Sort the results on a specific field.') do |sort| @opt[:sort] = sort end unless disable_sort_opts options.on('-p', '--page PAGE', Integer, 'Starting page for the results. Default is 0') do |page| @opt[:page] = page end options.on('-P', '--per-page PER_PAGE', Integer, 'The number of results on each page. Default is 100') do |per_page| @opt[:per_page] = per_page end set_filter_optparse_options!(options, @query_filter) end
Public Instance Methods
generate_paginated_query_string()
click to toggle source
# File lib/a2/mixins/paginated.rb, line 27 def generate_paginated_query_string query = generate_query_filters query << "&pagination.page=#{@opt[:page]}" if @opt[:page] query << "&pagination.page=#{@opt[:per_page]}" if @opt[:per_page] query << "&sorting.field=#{@opt[:sort]}" if @opt[:sort] query << "&sorting.order=#{@opt[:order]}" if @opt[:order] query end
with_paginated_filter_json() { |json| ... }
click to toggle source
# File lib/a2/mixins/paginated.rb, line 22 def with_paginated_filter_json(&block) json = generate_json_filters yield(json) end
with_paginated_filter_query() { |query_string| ... }
click to toggle source
# File lib/a2/mixins/paginated.rb, line 36 def with_paginated_filter_query(&block) query_string = generate_paginated_query_string yield(query_string) end