Class: ThreadSafety::Offense

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_safety/offense.rb

Constant Summary collapse

CALLER_SKIP =

Ruby 3.4 includes an extra Class#new frame in the call stack compared to Ruby 4.0

RUBY_VERSION >= "4.0" ? 2 : 3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, created_fiber, created_thread) ⇒ Offense

Returns a new instance of Offense.



10
11
12
13
14
15
16
17
# File 'lib/thread_safety/offense.rb', line 10

def initialize(object, created_fiber, created_thread)
  @object = object
  @created_fiber = created_fiber
  @created_thread = created_thread
  @access_fiber = Fiber.current
  @access_thread = Thread.current
  @backtrace = caller_locations(CALLER_SKIP).freeze
end

Instance Attribute Details

#access_fiberObject (readonly)

Returns the value of attribute access_fiber.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def access_fiber
  @access_fiber
end

#access_threadObject (readonly)

Returns the value of attribute access_thread.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def access_thread
  @access_thread
end

#backtraceObject (readonly)

Returns the value of attribute backtrace.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def backtrace
  @backtrace
end

#created_fiberObject (readonly)

Returns the value of attribute created_fiber.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def created_fiber
  @created_fiber
end

#created_threadObject (readonly)

Returns the value of attribute created_thread.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def created_thread
  @created_thread
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/thread_safety/offense.rb', line 5

def object
  @object
end

Instance Method Details

#to_sObject



19
20
21
# File 'lib/thread_safety/offense.rb', line 19

def to_s
  "#<ThreadSafety::Offense object=#{object} created_thread=#{created_thread} access_thread=#{access_thread} backtrace=#{backtrace[0]}>"
end