Module: AliexpressAPI::ThreadsafeAttributes::ClassMethods

Defined in:
lib/aliexpress_api/threadsafe_attributes.rb

Instance Method Summary collapse

Instance Method Details

#threadsafe_attribute(*attrs) ⇒ Object



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

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