Class: Karafka::Web::Ui::Controllers::Requests::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/ui/controllers/requests/params.rb

Overview

Internal representation of params with sane sanitization

Instance Method Summary collapse

Constructor Details

#initialize(request_params) ⇒ Params

Returns a new instance of Params.

Parameters:

  • request_params (Hash)

    raw hash with 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_offsetInteger

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.

Returns:

  • (Integer)

    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



61
62
63
64
65
66
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 61

def current_offset
  @current_offset ||= begin
    offset = @request_params.fetch('offset', -1).to_i
    offset < -1 ? -1 : offset
  end
end

#current_pageInteger

Note:

It does basic sanitization

Returns current page for paginated views.

Returns:

  • (Integer)

    current page for paginated views



43
44
45
46
47
48
49
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 43

def current_page
  @current_page ||= begin
    page = @request_params['page'].to_i

    page.positive? ? page : 1
  end
end

#current_partitionInteger

Returns currently selected partition or -1 if nothing provided.

Returns:

  • (Integer)

    currently selected partition or -1 if nothing provided



69
70
71
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 69

def current_partition
  @current_partition ||= @request_params.fetch('partition', -1).to_i
end

#current_rangeString

Returns Range type for charts we want to fetch.

Returns:

  • (String)

    Range type for charts we want to fetch



52
53
54
55
56
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 52

def current_range
  candidate = @request_params.fetch('range', 'seconds')
  candidate = ALLOWED_RANGES.first unless ALLOWED_RANGES.include?(candidate)
  candidate.to_sym
end

#current_searchHash

Returns current search or empty if no search query present.

Returns:

  • (Hash)

    current search or empty if no search query present



28
29
30
31
32
33
34
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 28

def current_search
  return @current_search if @current_search

  search = @request_params['search']

  @current_search = search.is_a?(Hash) ? search : {}
end

#current_sortString

Returns sort query value.

Returns:

  • (String)

    sort query value



37
38
39
# File 'lib/karafka/web/ui/controllers/requests/params.rb', line 37

def current_sort
  @current_sort ||= @request_params['sort'].to_s.downcase
end