Sha256: 72ceb4af3bd6095609c665b5fa620c8848b1dd93272104be3cb2082d437f4f16

Contents?: true

Size: 527 Bytes

Versions: 2

Compression:

Stored size: 527 Bytes

Contents

module Timeliness
  module ThreadsafeAttr
    def threadsafe_attr_accessor(*attrs)
      attrs.each do |attr|
        storage_name = "#{name}.#{attr}".freeze
        reader attr, storage_name
        writer attr, storage_name
      end
    end

    private
    def reader(attr, storage_name)
      define_method(attr) do
        Thread.current[storage_name]
      end
    end

    def writer(attr, storage_name)
      define_method("#{attr}=") do |value|
        Thread.current[storage_name] = value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timeliness-0.4.1 lib/timeliness/threadsafe_attr.rb
timeliness-0.4.0 lib/timeliness/threadsafe_attr.rb