Class: PeakFlowUtils::InheritedLocalVar

Inherits:
Object
  • Object
show all
Defined in:
lib/peak_flow_utils/inherited_local_var.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_value = nil) ⇒ InheritedLocalVar

Returns a new instance of InheritedLocalVar.



76
77
78
79
80
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 76

def initialize(new_value = nil)
  ObjectSpace.define_finalizer(self, PeakFlowUtils::InheritedLocalVar.method(:finalize))
  @identifier = PeakFlowUtils::InheritedLocalVar.identifier_for_object_id(__id__)
  Thread.inherited_local_vars_set(identifier => new_value)
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



60
61
62
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 60

def identifier
  @identifier
end

Class Method Details

.finalize(inherited_local_var_object_id) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 66

def self.finalize(inherited_local_var_object_id)
  identifier = PeakFlowUtils::InheritedLocalVar.identifier_for_object_id(inherited_local_var_object_id)
  Thread.inherited_local_vars_delete(identifier)
rescue Exception => e # rubocop:disable Lint/RescueException
  puts e.inspect # rubocop:disable Rails/Output
  puts e.backtrace # rubocop:disable Rails/Output

  raise e
end

.identifier_for_object_id(object_id) ⇒ Object



62
63
64
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 62

def self.identifier_for_object_id(object_id)
  "inherited_local_var_#{object_id}"
end

Instance Method Details

#valueObject



82
83
84
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 82

def value
  Thread.inherited_local_vars_fetch(identifier)
end

#value=(new_value) ⇒ Object



86
87
88
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 86

def value=(new_value)
  Thread.inherited_local_vars_set(identifier => new_value)
end