Class: BBK::App::Matchers::DeliveryInfo

Inherits:
Base
  • Object
show all
Defined in:
lib/bbk/app/matchers/delivery_info.rb

Instance Attribute Summary

Attributes inherited from Base

#rule

Instance Method Summary collapse

Methods inherited from Base

#==, #eql?, #hash, #keys_deep

Constructor Details

#initialize(rule) ⇒ DeliveryInfo

Returns a new instance of DeliveryInfo.



9
10
11
# File 'lib/bbk/app/matchers/delivery_info.rb', line 9

def initialize(rule)
  @rule = rule.with_indifferent_access
end

Instance Method Details

#match(_headers, _payload, delivery_info, *_args) ⇒ Object



13
14
15
16
17
18
# File 'lib/bbk/app/matchers/delivery_info.rb', line 13

def match(_headers, _payload, delivery_info, *_args)
  delivery_info = delivery_info.to_hash unless delivery_info.is_a? Hash
  match_impl(@rule, delivery_info.with_indifferent_access)
rescue StandardError
  nil
end

#match_impl(rule, data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/bbk/app/matchers/delivery_info.rb', line 20

def match_impl(rule, data)
  result = super
  if !result && (key_rule = rule[:routing_key])
    regexp_rule = Regexp.new("\\A#{key_rule.gsub('.', '\.').gsub('*', '\S+').gsub('#',
                                                                                  '.*')}\\Z")
    check = regexp_rule.match?(data[:routing_key])
    result = ({ 'routing_key' => data[:routing_key] } if check)
  end
  result
end