Module: AffiliationId

Defined in:
lib/affiliation_id.rb,
lib/affiliation_id/railtie.rb,
lib/affiliation_id/version.rb,
lib/affiliation_id/configuration.rb,
lib/affiliation_id/middleware/rack.rb,
lib/affiliation_id/middleware/rails.rb,
lib/affiliation_id/middleware/faraday.rb,
lib/affiliation_id/middleware/sidekiq_client.rb,
lib/affiliation_id/middleware/sidekiq_server.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Middleware Classes: Configuration, MissingCurrentId, Railtie

Constant Summary collapse

THREAD_KEY =
'AFFILIATION_ID'
SIDEKIQ_JOB_KEY =
'affiliation_id'
VERSION =
'0.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

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

Yields:



58
59
60
# File 'lib/affiliation_id.rb', line 58

def configure
  yield configuration
end

.current_idString

Returns the current Affiliation ID

Returns:

  • (String)

    Uniq Affiliation ID

Raises:



24
25
26
27
28
# File 'lib/affiliation_id.rb', line 24

def current_id
  raise MissingCurrentId if Thread.current[THREAD_KEY].nil? && configuration.enforce_explicit_current_id

  Thread.current[THREAD_KEY] ||= SecureRandom.uuid
end

.current_id=(value) ⇒ String

Sets a new ID to be used as Affiliation ID

Parameters:

  • value (String)

    of Affilication ID

Returns:

  • (String)

    Affiliation ID



37
38
39
# File 'lib/affiliation_id.rb', line 37

def current_id=(value)
  Thread.current[THREAD_KEY] = value
end

.renew_current_id!String

Renew the current Affiliation ID with a new one

Returns:

  • (String)

    Affiliation ID



46
47
48
# File 'lib/affiliation_id.rb', line 46

def renew_current_id!
  Thread.current[THREAD_KEY] = SecureRandom.uuid
end

.reset!Object



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

def reset!
  Thread.current[THREAD_KEY] = nil
end