Class: RailsPerformance::CurrentRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/thread/current_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id) ⇒ CurrentRequest

Returns a new instance of CurrentRequest.



21
22
23
24
25
26
27
# File 'lib/rails_performance/thread/current_request.rb', line 21

def initialize(request_id)
  @request_id = request_id
  @tracings   = []
  @ignore     = Set.new
  @data       = nil
  @record     = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/rails_performance/thread/current_request.rb', line 4

def data
  @data
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



3
4
5
# File 'lib/rails_performance/thread/current_request.rb', line 3

def ignore
  @ignore
end

#recordObject

Returns the value of attribute record.



5
6
7
# File 'lib/rails_performance/thread/current_request.rb', line 5

def record
  @record
end

#request_idObject (readonly)

Returns the value of attribute request_id.



3
4
5
# File 'lib/rails_performance/thread/current_request.rb', line 3

def request_id
  @request_id
end

#tracingsObject (readonly)

Returns the value of attribute tracings.



3
4
5
# File 'lib/rails_performance/thread/current_request.rb', line 3

def tracings
  @tracings
end

Class Method Details

.cleanupObject



15
16
17
18
19
# File 'lib/rails_performance/thread/current_request.rb', line 15

def CurrentRequest.cleanup
  RailsPerformance.log "----------------------------------------------------> CurrentRequest.cleanup !!!!!!!!!!!! -------------------------\n\n"
  RailsPerformance.skip = false
  Thread.current[:rp_current_request] = nil
end

.currentObject



11
12
13
# File 'lib/rails_performance/thread/current_request.rb', line 11

def CurrentRequest.current
  CurrentRequest.init
end

.initObject



7
8
9
# File 'lib/rails_performance/thread/current_request.rb', line 7

def CurrentRequest.init
  Thread.current[:rp_current_request] ||= CurrentRequest.new(SecureRandom.hex(16))
end

Instance Method Details

#trace(options = {}) ⇒ Object



29
30
31
# File 'lib/rails_performance/thread/current_request.rb', line 29

def trace(options = {})
  @tracings << options.merge(time: Time.current.to_i)
end