module ThreadsafeAttributes
Public Class Methods
included(klass)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 6 def self.included(klass) klass.extend(ClassMethods) end
Private Instance Methods
get_threadsafe_attribute(name, main_thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 31 def get_threadsafe_attribute(name, main_thread) if threadsafe_attribute_defined_by_thread?(name, Thread.current) get_threadsafe_attribute_by_thread(name, Thread.current) elsif threadsafe_attribute_defined_by_thread?(name, main_thread) value = get_threadsafe_attribute_by_thread(name, main_thread) value = value.dup if value.duplicable? set_threadsafe_attribute_by_thread(name, value, Thread.current) value end end
get_threadsafe_attribute_by_thread(name, thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 53 def get_threadsafe_attribute_by_thread(name, thread) thread.thread_variable_get "active.resource.#{name}.#{self.object_id}" end
set_threadsafe_attribute(name, value, main_thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 42 def set_threadsafe_attribute(name, value, main_thread) set_threadsafe_attribute_by_thread(name, value, Thread.current) unless threadsafe_attribute_defined_by_thread?(name, main_thread) set_threadsafe_attribute_by_thread(name, value, main_thread) end end
set_threadsafe_attribute_by_thread(name, value, thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 57 def set_threadsafe_attribute_by_thread(name, value, thread) thread.thread_variable_set "active.resource.#{name}.#{self.object_id}.defined", true thread.thread_variable_set "active.resource.#{name}.#{self.object_id}", value end
threadsafe_attribute_defined?(name, main_thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 49 def threadsafe_attribute_defined?(name, main_thread) threadsafe_attribute_defined_by_thread?(name, Thread.current) || ((Thread.current != main_thread) && threadsafe_attribute_defined_by_thread?(name, main_thread)) end
threadsafe_attribute_defined_by_thread?(name, thread)
click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 62 def threadsafe_attribute_defined_by_thread?(name, thread) thread.thread_variable_get "active.resource.#{name}.#{self.object_id}.defined" end