Class: Karafka::Web::Pro::Ui::Lib::Search::Matchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/pro/ui/lib/search/matchers/base.rb

Overview

Base class for all the search matchers Each matcher needs to have a class #name method and needs to respond to #call

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.active?(_topic_name) ⇒ Boolean

Allows to disable/enable certain matches that may be specific to certain types of data per topic. By default matchers are always active

Parameters:

  • _topic_name (String)

    name of the topic in the explorer

Returns:

  • (Boolean)

    should this matcher be active in the given topic



48
49
50
# File 'lib/karafka/web/pro/ui/lib/search/matchers/base.rb', line 48

def active?(_topic_name)
  true
end

.nameString

Returns name of the matcher based on the class name.

Returns:

  • (String)

    name of the matcher based on the class name



35
36
37
38
39
40
41
# File 'lib/karafka/web/pro/ui/lib/search/matchers/base.rb', line 35

def name
  # Insert a space before each uppercase letter, except the first one
  spaced_string = to_s.split('::').last.gsub(/(?<!^)([A-Z])/, ' \1')

  # Convert the first letter to uppercase and the rest to lowercase
  spaced_string[0].upcase + spaced_string[1..].downcase
end

Instance Method Details

#call(phrase, message) ⇒ Boolean

Returns true if found, otherwise false.

Parameters:

  • phrase (String)

    string phrase for search

  • message (Karafka::Messages::Message)

    message in which we search

Returns:

  • (Boolean)

    true if found, otherwise false

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/karafka/web/pro/ui/lib/search/matchers/base.rb', line 29

def call(phrase, message)
  raise NotImplementedError, 'Implement in a subclass'
end