Module: MsHeaderTrail

Defined in:
lib/ms_header_trail.rb,
lib/ms_header_trail/version.rb,
lib/ms_header_trail/configuration.rb

Overview

This service include the collected information passed into method ‘collect` to be retrieved later where will be used. In rack process, faraday connection or Bunny process

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.collect(attributes) ⇒ Object

Public: Collect the given parameters, which is set by user on start the capture process or during the Rack middleware



19
20
21
22
23
# File 'lib/ms_header_trail.rb', line 19

def collect(attributes)
  attributes.each_pair do |key, value|
    set(configuration.to_store(key), value.to_s)
  end
end

.configurationObject



54
55
56
# File 'lib/ms_header_trail.rb', line 54

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Public: Configure the process.

Examples

MsHeaderTrail.configure do |config|
  config.prefix_keyname = 'msht-'
end

Yields:



65
66
67
# File 'lib/ms_header_trail.rb', line 65

def configure
  yield configuration
end

.get(key) ⇒ Object

Public: Retrieve the given key



45
46
47
# File 'lib/ms_header_trail.rb', line 45

def get(key)
  Thread.current[key]
end

.resetObject

Public: Reset values into current thread



40
41
42
# File 'lib/ms_header_trail.rb', line 40

def reset
  current_thread_data.each { |key| Thread.current[key] = nil }
end

.retrieveObject

Public: Retrive the stored parameters, which was set by user during the Rack middleware, faraday connection or manually



27
28
29
30
# File 'lib/ms_header_trail.rb', line 27

def retrieve
  current_thread_data
    .each_with_object({}) { |key, memo| memo[configuration.from_store(key)] = get(key) }
end

.set(key, value) ⇒ Object

Public: Set the given key to the given value



50
51
52
# File 'lib/ms_header_trail.rb', line 50

def set(key, value)
  Thread.current[key] = value
end

.with(attributes) ⇒ Object

Public: Execute a block code after reset and collect data



33
34
35
36
37
# File 'lib/ms_header_trail.rb', line 33

def with(attributes)
  reset
  collect(attributes)
  yield
end