Class: FlowChat::Context

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/flow_chat/context.rb

Instance Method Summary collapse

Methods included from Instrumentation

#instrument, instrument

Constructor Details

#initializeContext

Returns a new instance of Context.



5
6
7
8
9
10
11
12
# File 'lib/flow_chat/context.rb', line 5

def initialize
  @data = {}.with_indifferent_access

  # Use instrumentation for context creation
  self.class.instrument(Events::CONTEXT_CREATED, {
    gateway: @data["request.gateway"]
  })
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
17
18
# File 'lib/flow_chat/context.rb', line 14

def [](key)
  value = @data[key]
  FlowChat.logger.debug { "Context: Getting '#{key}' = #{value.inspect}" } if key != "session.store" # Avoid logging session store object
  value
end

#[]=(key, value) ⇒ Object



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

def []=(key, value)
  FlowChat.logger.debug { "Context: Setting '#{key}' = #{value.inspect}" } if key != "session.store" && key != "controller" # Avoid logging large objects
  @data[key] = value
end

#controllerObject



39
# File 'lib/flow_chat/context.rb', line 39

def controller = @data["controller"]

#flowObject

def request = controller.request



43
# File 'lib/flow_chat/context.rb', line 43

def flow = @data["flow.class"]

#inputObject



25
# File 'lib/flow_chat/context.rb', line 25

def input = @data["request.input"]

#input=(value) ⇒ Object



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

def input=(value)
  FlowChat.logger.debug { "Context: Setting input = '#{value}'" }
  @data["request.input"] = value
end

#sessionObject



32
# File 'lib/flow_chat/context.rb', line 32

def session = @data["session"]

#session=(value) ⇒ Object



34
35
36
37
# File 'lib/flow_chat/context.rb', line 34

def session=(value)
  FlowChat.logger.debug { "Context: Setting session = #{value.class.name}" }
  @data["session"] = value
end