Module: ThreadsafeAttributes::ClassMethods

Defined in:
lib/active_resource/threadsafe_attributes.rb

Instance Method Summary collapse

Instance Method Details

#threadsafe_attribute(*attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_resource/threadsafe_attributes.rb', line 11

def threadsafe_attribute(*attrs)
  main_thread = Thread.main # remember this, because it could change after forking

  attrs.each do |attr|
    define_method attr do
      get_threadsafe_attribute(attr, main_thread)
    end

    define_method "#{attr}=" do |value|
      set_threadsafe_attribute(attr, value, main_thread)
    end

    define_method "#{attr}_defined?" do
      threadsafe_attribute_defined?(attr, main_thread)
    end
  end
end