Class: Banter::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/banter/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params_hash = {}) ⇒ Context

acceptable values employee - employee id that the context could have user_id - ender user id of call unique_id - unique identifier (could be request.uuid most of the time) orig_ip_address - ip address of originating requester



8
9
10
# File 'lib/banter/context.rb', line 8

def initialize(params_hash = {})
  @data = Hashie::Mash.new(params_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

USE AS INFREQUENTLY AS POSSIBLE. Only use it if you absolutely must as really, we want context in the object, and not the kitchen sink, which is what this will turn out to be if we use regularly use this mechanism.



56
57
58
59
60
61
62
63
# File 'lib/banter/context.rb', line 56

def method_missing(method_name, *arguments, &block)
  if @data.key?(method_name)
    @data[method_name]
  else
    super
  end

end

Class Method Details

.clear!Object



48
49
50
# File 'lib/banter/context.rb', line 48

def self.clear!
  Thread.current['pubsub_context'] = nil
end

.from_json(data_hash) ⇒ Object



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

def self.from_json(data_hash)
  ::Banter::Context.new(data_hash)
end

.instanceObject



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

def self.instance
  Thread.current['pubsub_context'] || {}
end

.setup_context(attrs = {}) ⇒ Object



44
45
46
# File 'lib/banter/context.rb', line 44

def self.setup_context(attrs = {})
  Thread.current['pubsub_context'] = self.new(attrs)
end

Instance Method Details

#applicationObject



36
37
38
# File 'lib/banter/context.rb', line 36

def application
  @data.application
end

#as_jsonObject



20
21
22
# File 'lib/banter/context.rb', line 20

def as_json
  @data.as_json
end

#employee_idObject



16
17
18
# File 'lib/banter/context.rb', line 16

def employee_id
  @data.employee_id
end

#originating_ip_addressObject



28
29
30
# File 'lib/banter/context.rb', line 28

def originating_ip_address
  @data.orig_ip_address
end

#serializeObject



32
33
34
# File 'lib/banter/context.rb', line 32

def serialize
  @data.as_json
end

#unique_idObject



24
25
26
# File 'lib/banter/context.rb', line 24

def unique_id
  @data.unique_id
end

#user_idObject



12
13
14
# File 'lib/banter/context.rb', line 12

def user_id
  @data.user_id
end