thread_local_accessor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv-version
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ script:
7
+ - bundle exec rake test
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Thread Local Accessor 0.1.0 (April 18, 2012)
4
+
5
+ * First public release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexey Vakhov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # ThreadLocalAccessor
2
+
3
+ Thread local accessor. An idea from [here](http://coderrr.wordpress.com/2008/04/10/lets-stop-polluting-the-threadcurrent-hash/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'thread_local_accessor'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install thread_local_accessor
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Status
24
+
25
+ [<img src="https://secure.travis-ci.org/avakhov/thread_local_accessor.png"/>](http://travis-ci.org/avakhov/thread_local_accessor)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = false
10
+ end
@@ -0,0 +1,3 @@
1
+ module ThreadLocalAccessor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ require "thread_local_accessor/version"
2
+
3
+ # An idea from http://coderrr.wordpress.com/2008/04/10/lets-stop-polluting-the-threadcurrent-hash/
4
+ class Class
5
+ def thread_local_accessor name, options = {}
6
+ m = Module.new
7
+ m.module_eval %{
8
+ def #{name}
9
+ k = ((Class === self ? self : self.class).object_id.to_s + '_#{name}').to_sym
10
+ if Thread.current.key?(k)
11
+ Thread.current[k]
12
+ else
13
+ #{options[:default].inspect}
14
+ end
15
+ end
16
+
17
+ def #{name}=(val)
18
+ k = ((Class === self ? self : self.class).object_id.to_s + '_#{name}').to_sym
19
+ Thread.current[k] = val
20
+ end
21
+ }
22
+
23
+ class_eval do
24
+ include m
25
+ extend m
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ require 'test/unit'
2
+ require 'thread_local_accessor'
3
+
4
+ # http://coderrr.wordpress.com/2008/04/10/lets-stop-polluting-the-threadcurrent-hash/
5
+ class ThreadedLib
6
+ thread_local_accessor :some_setting, :default => :default
7
+ end
8
+
9
+ class TestThreadedClassAttrAccessor < Test::Unit::TestCase
10
+ def test_that_it_works!
11
+ instance = ThreadedLib.new
12
+
13
+ ThreadedLib.some_setting = 5
14
+
15
+ assert_equal 5, ThreadedLib.some_setting
16
+ assert_equal 5, instance.some_setting
17
+
18
+ Thread.new {
19
+ instance.some_setting = 10
20
+
21
+ assert_equal 10, ThreadedLib.some_setting
22
+ assert_equal 10, instance.some_setting
23
+ }.join
24
+
25
+ Thread.new { assert_equal :default, ThreadedLib.some_setting }.join
26
+
27
+ assert_equal 5, ThreadedLib.some_setting
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/thread_local_accessor/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexey Vakhov"]
6
+ gem.email = ["vakhov@gmail.com"]
7
+ gem.description = %q{Thread Local Accessor}
8
+ gem.summary = %q{Thread Safe Local Accessor}
9
+ gem.homepage = "https://github.com/avakhov/thread_local_accessor"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "thread_local_accessor"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ThreadLocalAccessor::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thread_local_accessor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Vakhov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &79427970 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *79427970
25
+ description: Thread Local Accessor
26
+ email:
27
+ - vakhov@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .travis.yml
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - lib/thread_local_accessor.rb
40
+ - lib/thread_local_accessor/version.rb
41
+ - test/thread_local_accessor_test.rb
42
+ - thread_local_accessor.gemspec
43
+ homepage: https://github.com/avakhov/thread_local_accessor
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ segments:
56
+ - 0
57
+ hash: -587324531
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
65
+ - 0
66
+ hash: -587324531
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.17
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Thread Safe Local Accessor
73
+ test_files: []