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
-
#[](key) ⇒ Object
Value of the requested param.
-
#bool(key) ⇒ Boolean
Boolean key value.
-
#current_offset ⇒ Integer
Offset from which we want to start.
-
#current_page ⇒ Integer
Current page for paginated views.
-
#current_partition ⇒ Integer
Currently selected partition or -1 if nothing provided.
-
#current_range ⇒ String
Range type for charts we want to fetch.
-
#current_search ⇒ Hash
Current search or empty if no search query present.
-
#current_sort ⇒ String
Sort query value.
-
#fetch(*args) ⇒ Object
Fetched object.
-
#initialize(request_params) ⇒ Params
constructor
A new instance of Params.
-
#int(key) ⇒ Integer
Integer value of the key.
-
#str(key) ⇒ String
Stringified key value.
Constructor Details
#initialize(request_params) ⇒ Params
Returns a new instance of Params.
30 31 32 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 30 def initialize(request_params) @request_params = request_params end |
Instance Method Details
#[](key) ⇒ Object
Returns value of the requested param.
36 37 38 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 36 def [](key) fetch(key.to_s) end |
#bool(key) ⇒ Boolean
Returns boolean key value.
55 56 57 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 55 def bool(key) ALLOWED_BOOLEAN_TRUE.include?(self[key]) end |
#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.
99 100 101 102 103 104 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 99 def current_offset @current_offset ||= begin offset = @request_params.fetch('offset', -1).to_i offset < -1 ? -1 : offset end end |
#current_page ⇒ Integer
It does basic sanitization
Returns current page for paginated views.
81 82 83 84 85 86 87 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 81 def current_page @current_page ||= begin page = @request_params['page'].to_i page.positive? ? page : 1 end end |
#current_partition ⇒ Integer
Returns currently selected partition or -1 if nothing provided.
107 108 109 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 107 def current_partition @current_partition ||= @request_params.fetch('partition', -1).to_i end |
#current_range ⇒ String
Returns Range type for charts we want to fetch.
90 91 92 93 94 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 90 def current_range candidate = @request_params.fetch('range', 'seconds') candidate = ALLOWED_RANGES.first unless ALLOWED_RANGES.include?(candidate) candidate.to_sym end |
#current_search ⇒ Hash
Returns current search or empty if no search query present.
66 67 68 69 70 71 72 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 66 def current_search return @current_search if @current_search search = @request_params['search'] @current_search = search.is_a?(Hash) ? search : {} end |
#current_sort ⇒ String
Returns sort query value.
75 76 77 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 75 def current_sort @current_sort ||= @request_params['sort'].to_s.downcase end |
#fetch(*args) ⇒ Object
Returns fetched object.
42 43 44 45 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 42 def fetch(*args) args[0] = args[0].to_s @request_params.fetch(*args) end |
#int(key) ⇒ Integer
Returns integer value of the key.
49 50 51 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 49 def int(key) self[key].to_i end |
#str(key) ⇒ String
Returns stringified key value.
61 62 63 |
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 61 def str(key) self[key].to_s end |