Class: Karafka::Web::Ui::Controllers::Requests::Params
- Inherits:
-
Object
- Object
- Karafka::Web::Ui::Controllers::Requests::Params
- Defined in:
- lib/karafka/web/ui/controllers/requests/params.rb
Overview
Internal representation of params with sane sanitization
Instance Method Summary collapse
-
#current_offset ⇒ Integer
Offset from which we want to start.
-
#current_page ⇒ Integer
Current page for paginated views.
-
#current_range ⇒ String
Range type for charts we want to fetch.
-
#initialize(request_params) ⇒ Params
constructor
A new instance of Params.
-
#sort ⇒ String
Sort query value.
Constructor Details
#initialize(request_params) ⇒ Params
Returns a new instance of Params.
23 24 25 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 23 def initialize(request_params) @request_params = request_params end |
Instance Method Details
#current_offset ⇒ Integer
Returns offset from which we want to start. -1
indicates, that we want to show the first page discovered based on the high watermark offset. If no offset is provided, we go with the high offset first page approach.
52 53 54 55 56 57 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 52 def current_offset @current_offset ||= begin offset = @request_params.fetch('offset', -1).to_i offset < -1 ? -1 : offset end end |
#current_page ⇒ Integer
Note:
It does basic sanitization
Returns current page for paginated views.
34 35 36 37 38 39 40 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 34 def current_page @current_page ||= begin page = @request_params['page'].to_i page.positive? ? page : 1 end end |
#current_range ⇒ String
Returns Range type for charts we want to fetch.
43 44 45 46 47 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 43 def current_range candidate = @request_params.fetch('range', 'seconds') candidate = ALLOWED_RANGES.first unless ALLOWED_RANGES.include?(candidate) candidate.to_sym end |
#sort ⇒ String
Returns sort query value.
28 29 30 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 28 def sort @sort ||= @request_params['sort'].to_s.downcase end |