Class: RubyJard::ThreadInfo
- Inherits:
-
Object
- Object
- RubyJard::ThreadInfo
- Defined in:
- lib/ruby_jard/thread_info.rb
Overview
A wrapper for thread object to prevent direc access to thread data
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
rubocop:disable Style/CaseLikeIf.
- #alive? ⇒ Boolean
- #backtrace_locations ⇒ Object
-
#initialize(thread) ⇒ ThreadInfo
constructor
A new instance of ThreadInfo.
- #name ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(thread) ⇒ ThreadInfo
Returns a new instance of ThreadInfo.
32 33 34 35 36 37 38 |
# File 'lib/ruby_jard/thread_info.rb', line 32 def initialize(thread) raise RubyJard::Error, 'Expected Thread object or nil' if !thread.is_a?(::Thread) && !thread.nil? @thread = thread @id = thread&.object_id @label = self.class.generate_label_for(@id) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/ruby_jard/thread_info.rb', line 30 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
30 31 32 |
# File 'lib/ruby_jard/thread_info.rb', line 30 def label @label end |
Class Method Details
.clear_labels ⇒ Object
12 13 14 15 |
# File 'lib/ruby_jard/thread_info.rb', line 12 def clear_labels @labels = {} @next_label = 0 end |
.generate_label_for(id) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ruby_jard/thread_info.rb', line 22 def generate_label_for(id) return '' if id.nil? return labels[id] if labels[id] labels[id] = next_label.to_s end |
.labels ⇒ Object
8 9 10 |
# File 'lib/ruby_jard/thread_info.rb', line 8 def labels @labels ||= {} end |
.next_label ⇒ Object
17 18 19 20 |
# File 'lib/ruby_jard/thread_info.rb', line 17 def next_label @next_label ||= 0 @next_label += 1 end |
Instance Method Details
#==(other) ⇒ Object
rubocop:disable Style/CaseLikeIf
58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_jard/thread_info.rb', line 58 def ==(other) if other.is_a?(::Thread) @thread == other elsif other.is_a?(ThreadInfo) @id == other.id else raise RubyJard::Error, 'Invalid comparation' end end |
#alive? ⇒ Boolean
49 50 51 |
# File 'lib/ruby_jard/thread_info.rb', line 49 def alive? @thread&.alive? || false end |
#backtrace_locations ⇒ Object
53 54 55 |
# File 'lib/ruby_jard/thread_info.rb', line 53 def backtrace_locations @thread&.backtrace_locations || [] end |
#name ⇒ Object
40 41 42 |
# File 'lib/ruby_jard/thread_info.rb', line 40 def name @thread&.name end |
#status ⇒ Object
44 45 46 47 |
# File 'lib/ruby_jard/thread_info.rb', line 44 def status s = @thread&.status s == false ? 'exited' : s end |