Class: Kazoo::PatternSubscription
- Inherits:
-
Subscription
- Object
- Subscription
- Kazoo::PatternSubscription
- Defined in:
- lib/kazoo/subscription.rb
Overview
PatternSubscription describes a subscription based on a regular expression that serves as either a whitelist or blacklist filter for all topics available in a Kafka cluster.
Constant Summary collapse
- PATTERN_TYPES =
[:black_list, :white_list].freeze
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Attributes inherited from Subscription
Instance Method Summary collapse
-
#black_list? ⇒ Boolean
Returns true if this subscription uses a blacklist pattern.
-
#has_topic?(topic) ⇒ Boolean
Returns true if the whitelist or blacklist does not filter out the provided topic.
-
#initialize(regexp, pattern: :white_list, **kwargs) ⇒ PatternSubscription
constructor
A new instance of PatternSubscription.
-
#white_list? ⇒ Boolean
Returns true if this subscription uses a whitelist pattern.
Methods inherited from Subscription
build, #eql?, everything, from_json, #hash, #inspect, #partitions, #to_json, topic_name, #topics
Constructor Details
#initialize(regexp, pattern: :white_list, **kwargs) ⇒ PatternSubscription
Returns a new instance of PatternSubscription.
185 186 187 188 189 |
# File 'lib/kazoo/subscription.rb', line 185 def initialize(regexp, pattern: :white_list, **kwargs) super(**kwargs) raise ArgumentError, "#{pattern.inspect} is not a valid pattern type" unless PATTERN_TYPES.include?(pattern) @regexp, @pattern = regexp, pattern end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
183 184 185 |
# File 'lib/kazoo/subscription.rb', line 183 def pattern @pattern end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
183 184 185 |
# File 'lib/kazoo/subscription.rb', line 183 def regexp @regexp end |
Instance Method Details
#black_list? ⇒ Boolean
Returns true if this subscription uses a blacklist pattern
197 198 199 |
# File 'lib/kazoo/subscription.rb', line 197 def black_list? pattern == :black_list end |
#has_topic?(topic) ⇒ Boolean
Returns true if the whitelist or blacklist does not filter out the provided topic.
202 203 204 205 206 207 |
# File 'lib/kazoo/subscription.rb', line 202 def has_topic?(topic) case pattern when :white_list; topic.name =~ regexp when :black_list; topic.name !~ regexp end end |
#white_list? ⇒ Boolean
Returns true if this subscription uses a whitelist pattern
192 193 194 |
# File 'lib/kazoo/subscription.rb', line 192 def white_list? pattern == :white_list end |