Module: Grape::Formatter::Paginater
- Defined in:
- lib/paginater.rb,
lib/paginater/core.rb,
lib/paginater/constants.rb,
lib/paginater/formatter.rb,
lib/paginater/page/base_page.rb,
lib/paginater/page/page_links.rb
Defined Under Namespace
Modules: Constants, Core Classes: BasePage, PageLinks
Constant Summary
Constants included from Constants
Constants::DefaultPage, Constants::DefaultPageSize, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::KaminariParam, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OneHour, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::SetCookie, Constants::SimpleParam, Constants::WrapperParam
Class Attribute Summary collapse
-
.endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
.env ⇒ Object
readonly
Returns the value of attribute env.
-
.format ⇒ Object
readonly
Returns the value of attribute format.
-
.original ⇒ Object
readonly
Returns the value of attribute original.
-
.original_count ⇒ Object
readonly
Returns the value of attribute original_count.
-
.page_requested ⇒ Object
readonly
Returns the value of attribute page_requested.
-
.total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Methods included from Core
page_count, paginate, simple, total_pages
Class Attribute Details
.endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
12 13 14 |
# File 'lib/paginater/formatter.rb', line 12 def endpoint @endpoint end |
.env ⇒ Object (readonly)
Returns the value of attribute env.
12 13 14 |
# File 'lib/paginater/formatter.rb', line 12 def env @env end |
.format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/paginater/formatter.rb', line 12 def format @format end |
.original ⇒ Object (readonly)
Returns the value of attribute original.
12 13 14 |
# File 'lib/paginater/formatter.rb', line 12 def original @original end |
.original_count ⇒ Object (readonly)
Returns the value of attribute original_count.
13 14 15 |
# File 'lib/paginater/formatter.rb', line 13 def original_count @original_count end |
.page_requested ⇒ Object (readonly)
Returns the value of attribute page_requested.
13 14 15 |
# File 'lib/paginater/formatter.rb', line 13 def page_requested @page_requested end |
.total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
13 14 15 |
# File 'lib/paginater/formatter.rb', line 13 def total_pages @total_pages end |
Class Method Details
.call(object, env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/paginater/formatter.rb', line 15 def call(object, env) @env = env @endpoint = env['api.endpoint'] @format = env['api.format'] @original = object check_params case endpoint.[:route_options][:paginater] when KaminariParam Kaminari.configure do |config| config.default_per_page = 25 #=> 25? end if is_paginable? # TODO consider also options as :limit => x and :offset => y @paginated = Kaminari.paginate_array(original.to_a).page(endpoint.params[:page]).per(endpoint.params[:size]) else @paginated = original.page(endpoint.params[:page]).per(endpoint.params[:size]) end when SimpleParam @paginated = paginate(original, endpoint.params[:page], endpoint.params[:size]) when WrapperParam # deprecating... @paginated = wrap_content(paginate(original, endpoint.params[:page], endpoint.params[:size])) else @paginated = original end case format when :txt return @paginated.to_s if @paginated.respond_to?(:to_s) when :json Grape::Formatter::Json.call(@paginated, env) else raise PaginaterError, "format #{format} unknown" end end |