Module: Rack::ActionLogger::Container

Defined in:
lib/rack/action_logger/container.rb

Constant Summary collapse

THREAD_KEY =
:rack_action_logger
EXPORT_KEYS =
[:rack_action_logger_attributes]

Class Method Summary collapse

Class Method Details

.clearObject



14
15
16
# File 'lib/rack/action_logger/container.rb', line 14

def clear
  Thread.current[THREAD_KEY] = nil
end

.exportObject



57
58
59
60
61
62
63
64
# File 'lib/rack/action_logger/container.rb', line 57

def export
  # ここenumerableで置き換える
  hash = {}
  EXPORT_KEYS.each do |key|
    hash[key] = store[key] if store[key]
  end
  hash
end

.get_append_logsObject



33
34
35
# File 'lib/rack/action_logger/container.rb', line 33

def get_append_logs
  store[:rack_action_logger_append_logs] ||= []
end

.get_attributesObject



42
43
44
# File 'lib/rack/action_logger/container.rb', line 42

def get_attributes
  store[:rack_action_logger_attributes] ||= {}
end

.get_is_emit_startedObject



22
23
24
# File 'lib/rack/action_logger/container.rb', line 22

def get_is_emit_started
  store[:rack_action_logger_emit_started] ||= false
end

.get_request_logObject



53
54
55
# File 'lib/rack/action_logger/container.rb', line 53

def get_request_log
  store[:rack_action_logger_request_log] ||= {}
end

.import(hash) ⇒ Object



66
67
68
69
70
71
# File 'lib/rack/action_logger/container.rb', line 66

def import(hash)
  hash.symbolize_keys.each do |key, value|
    next unless EXPORT_KEYS.include? key
    store[key] = value
  end
end

.merge_attributes(attributes) ⇒ Object



37
38
39
40
# File 'lib/rack/action_logger/container.rb', line 37

def merge_attributes(attributes)
  return unless is_valid_hash attributes
  get_attributes.merge! attributes
end

.set_append_log(hash, tag = nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/rack/action_logger/container.rb', line 26

def set_append_log(hash, tag=nil)
  return unless is_valid_hash hash
  return unless is_valid_tag tag
  hash[:tag] = tag
  get_append_logs.push(hash)
end

.set_is_emit_startedObject



18
19
20
# File 'lib/rack/action_logger/container.rb', line 18

def set_is_emit_started
  store[:rack_action_logger_emit_started] = true
end

.set_request_log(hash, tag = nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/rack/action_logger/container.rb', line 46

def set_request_log(hash, tag=nil)
  return unless is_valid_hash hash
  return unless is_valid_tag tag
  hash[:tag] = tag
  get_request_log.merge! hash
end

.storeObject



10
11
12
# File 'lib/rack/action_logger/container.rb', line 10

def store
  Thread.current[THREAD_KEY] ||= {}
end