stas/jsonapi.rb

new jsonapi_page_size option

fluxsaas opened this issue ยท 3 comments

Hello!

regarding the new jsonapi_page_size implementation, i would like to suggest to always call the method jsonapi_page_size even if the params page[size] is passed to the request:

def jsonapi_pagination_params
pagination = params[:page].try(:slice, :number, :size) || {}
per_page = pagination[:size].to_f.to_i
per_page = jsonapi_page_size if per_page < 1
num = [1, pagination[:number].to_f.to_i].max
[(num - 1) * per_page, per_page, num]
end

a use case could be to implement a logic to set/overwrite the max size of a response:

def jsonapi_page_size
  pagination = params[:page].try(:size) || {}
  per_page = pagination[:size] || 50
  per_page = 50 if per_page.to_f.to_i > 50
  return per_page
end

best โœŒ๏ธ

stas commented

Hey @fluxsaas!
Would you be kind to send a PR please ๐Ÿ˜ƒ ๐Ÿ™‡

@stas

sure, do you want to raise an exception if per_page < 1 or just let the user handle the situation?

best

stas commented

There should be no exceptions. Thank you!