module ThreadsafeAttributes

Public Class Methods

included(klass) click to toggle source
# File lib/active_resource/threadsafe_attributes.rb, line 4
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 30
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 52
def get_threadsafe_attribute_by_thread(name, thread)
  thread["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 41
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 56
def set_threadsafe_attribute_by_thread(name, value, thread)
  thread["active.resource.#{name}.#{self.object_id}.defined"] = true
  thread["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 48
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 61
def threadsafe_attribute_defined_by_thread?(name, thread)
  thread["active.resource.#{name}.#{self.object_id}.defined"]
end