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.



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

def initialize(new_value = nil)
  ObjectSpace.define_finalizer(self, PeakFlowUtils::InheritedLocalVar.method(:finalize))

  @identifier = "inherited_local_var_#{__id__}"

  Thread.inherited_local_vars_set(identifier => new_value)
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



58
59
60
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 58

def identifier
  @identifier
end

Class Method Details

.finalize(inherited_local_var_object_id) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/peak_flow_utils/inherited_local_var.rb', line 60

def self.finalize(inherited_local_var_object_id)
  Thread.inherited_local_vars_delete("inherited_local_var_#{inherited_local_var_object_id}")
rescue Exception => e # rubocop:disable Lint/RescueException
  puts e.inspect # rubocop:disable Rails/Output
  puts e.backtrace # rubocop:disable Rails/Output

  raise e
end

Instance Method Details

#valueObject



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

def value
  Thread.inherited_local_vars_fetch(identifier)
end

#value=(new_value) ⇒ Object



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

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