Sha256: f945e6ce8e6ca98caa347c0eecd9a4a668a16ef6fd22b2b174c03f932bb33a27

Contents?: true

Size: 353 Bytes

Versions: 26

Compression:

Stored size: 353 Bytes

Contents

class Module
  def thread_local_attribute(name, &block)
    proc = Proc.new if block_given?
    key = "tls:#{name}"

    singleton_class.class_eval do
      define_method(name) do
        Thread.current[key] ||= proc ? proc.call : nil
      end

      define_method("#{name}=") do |value|
        Thread.current[key] = value
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
radiospiel-app-0.2.3 lib/core-extensions/tls.rb
radiospiel-app-0.2.2 lib/core-extensions/tls.rb
radiospiel-app-0.2.1 lib/core-extensions/tls.rb
radiospiel-app-0.2.0 lib/core-extensions/tls.rb
radiospiel-app-0.1.1 lib/core-extensions/tls.rb
radiospiel-app-0.1.0 lib/core-extensions/tls.rb