Class: Blinkbox::CommonMessaging::HeaderDetectors

Inherits:
Object
  • Object
show all
Defined in:
lib/blinkbox/common_messaging/header_detectors.rb,
lib/blinkbox/common_messaging/header_detectors/detect_remote_uris.rb

Constant Summary collapse

@@header_detectors =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ HeaderDetectors

Returns a new instance of HeaderDetectors.



4
5
6
# File 'lib/blinkbox/common_messaging/header_detectors.rb', line 4

def initialize(obj)
  @obj = obj
end

Class Method Details

.register(method_name) ⇒ Object



15
16
17
# File 'lib/blinkbox/common_messaging/header_detectors.rb', line 15

def self.register(method_name)
  @@header_detectors << method_name
end

Instance Method Details

#detect_remote_uris(original_headers) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/blinkbox/common_messaging/header_detectors/detect_remote_uris.rb', line 2

def detect_remote_uris(original_headers)
  hash = @obj.to_hash.extend(ExtraHashMethods)
  deep_keys = hash.deep_key_select do |h|
    h["type"] == "remote"
  end
  if !deep_keys.empty?
    original_headers.merge!(
      "has_remote_uris" => true,
      "remote_uris" => deep_keys
    )
  end
  original_headers
end

#modified_headers(original_headers = {}) ⇒ Object



8
9
10
11
12
13
# File 'lib/blinkbox/common_messaging/header_detectors.rb', line 8

def modified_headers(original_headers = {})
  @@header_detectors.each do |m|
    original_headers = send(m, original_headers)
  end
  original_headers
end