tool 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -7
- data/.travis.yml +6 -2
- data/README.md +89 -6
- data/Rakefile +4 -0
- data/lib/tool/equality_map.rb +4 -0
- data/lib/tool/version.rb +1 -1
- data/spec/equality_map_spec.rb +3 -0
- data/spec/thread_local_spec.rb +5 -0
- data/tool.gemspec +1 -0
- metadata +55 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91786fb78ed736327ffe723e946be2fd67267a73
|
4
|
+
data.tar.gz: 22ebe6e6931dab1c0c2d6ace6030875f71512622
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae28a3fc4f351498e3f776c931405caa0b69edcadcd7a87fce4c0a0c7284192f18ca27d9bbb172b821b8b0a0f2d17342baa890ca280fe494f3111c31bb97d378
|
7
|
+
data.tar.gz: e6f9b32b4ff5564f99346817ff4ca298ce557c171c55cdc4c0a18dddcd78898b927ba2ea695171b6c3e3b964bc3d9e4a3594205ab79f3849486ad20e4650b867
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,93 @@
|
|
1
1
|
*Make sure you view the correct docs: [latest release](http://rubydoc.info/gems/tool/frames), [master](http://rubydoc.info/github/rkh/tool/master/frames).*
|
2
2
|
|
3
|
-
|
3
|
+
Welcome to [Tool](http://www.youtube.com/watch?v=mYKLvYGqaC0), the general purpose Ruby library used by Sinatra 2.0, Mustermann and related projects.
|
4
4
|
|
5
|
-
|
5
|
+
## Tool::Decoration
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
Mixin for easy method decorations.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
class Frank
|
11
|
+
extend Tool::Decoration
|
12
|
+
def self.get(path, &block)
|
13
|
+
decorate(block) do |method|
|
14
|
+
puts "mapping GET #{path} to #{method}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class MyApp < Frank
|
20
|
+
get '/hi' do
|
21
|
+
"Hello World"
|
22
|
+
end
|
23
|
+
|
24
|
+
get '/'; get '/index.php'
|
25
|
+
def index
|
26
|
+
"This is the index page."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Tool::EqualityMap
|
32
|
+
|
33
|
+
Weak reference caching based on key equality.
|
34
|
+
Used for caching.
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
class ExpensiveComputation
|
38
|
+
@map = Tool::EqualityMap.new
|
39
|
+
|
40
|
+
def self.new(*args)
|
41
|
+
@map.fetch(*args) { super }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Note that `fetch` is not guaranteed to return the object, even if it has not been
|
47
|
+
garbage collected yet, especially when used concurrently. Therefore, the block passed to `fetch` has to
|
48
|
+
be idempotent.
|
49
|
+
|
50
|
+
## Tool::ThreadLocal
|
51
|
+
|
52
|
+
Have thread local values without them actually being thread global.
|
53
|
+
|
54
|
+
Advantages:
|
55
|
+
|
56
|
+
* Values for all threads are garbage collected when ThreadLocal instance is.
|
57
|
+
* Values for specific thread are garbage collected when thread is.
|
58
|
+
* No hidden global state.
|
59
|
+
* Supports other data types besides hashes.
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
local = Tool::ThreadLocal.new
|
63
|
+
local[:key] = "value"
|
64
|
+
|
65
|
+
Thread.new do
|
66
|
+
local[:key] = "other value"
|
67
|
+
puts local[:key] # other value
|
68
|
+
end.join
|
69
|
+
|
70
|
+
puts local[:key] # value
|
71
|
+
```
|
72
|
+
|
73
|
+
Usage with a pre-filled array:
|
74
|
+
|
75
|
+
``` ruby
|
76
|
+
local = Tool::ThreadLocal.new([:foo])
|
77
|
+
local << :bar
|
78
|
+
|
79
|
+
Thread.new { p local }.join # [:foo]
|
80
|
+
p local # [:foo, :bar]
|
81
|
+
```
|
82
|
+
|
83
|
+
## Tool::WarningFilter
|
84
|
+
|
85
|
+
Enables Ruby's built-in warnings (-w) but filters out those caused by third-party gems.
|
86
|
+
Does not invlove any manual set up.
|
87
|
+
|
88
|
+
``` ruby
|
89
|
+
require 'tool/warning_filter'
|
90
|
+
|
91
|
+
Foo = 10
|
92
|
+
Foo = 20
|
93
|
+
```
|
data/Rakefile
ADDED
data/lib/tool/equality_map.rb
CHANGED
data/lib/tool/version.rb
CHANGED
data/spec/equality_map_spec.rb
CHANGED
@@ -5,13 +5,16 @@ describe Tool::EqualityMap do
|
|
5
5
|
after { GC.enable }
|
6
6
|
|
7
7
|
describe :fetch do
|
8
|
+
subject { Tool::EqualityMap.new }
|
8
9
|
specify 'with existing entry' do
|
10
|
+
next if subject.is_a? Hash
|
9
11
|
subject.fetch("foo") { "foo" }
|
10
12
|
result = subject.fetch("foo") { "bar" }
|
11
13
|
expect(result).to be == "foo"
|
12
14
|
end
|
13
15
|
|
14
16
|
specify 'with GC-removed entry' do
|
17
|
+
next if subject.is_a? Hash
|
15
18
|
subject.fetch("foo") { "foo" }
|
16
19
|
expect(subject.map).to receive(:[]).and_return(nil)
|
17
20
|
result = subject.fetch("foo") { "bar" }
|
data/spec/thread_local_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'tool/thread_local'
|
|
2
2
|
|
3
3
|
describe Tool::ThreadLocal do
|
4
4
|
describe :__getobj__ do
|
5
|
+
subject { Tool::ThreadLocal.new }
|
6
|
+
|
5
7
|
specify 'normal access' do
|
6
8
|
subject[:foo] = 'bar'
|
7
9
|
expect(subject[:foo]).to be == 'bar'
|
@@ -41,6 +43,8 @@ describe Tool::ThreadLocal do
|
|
41
43
|
end
|
42
44
|
|
43
45
|
describe :__size__ do
|
46
|
+
subject { Tool::ThreadLocal.new }
|
47
|
+
|
44
48
|
specify 'with one thread' do
|
45
49
|
subject[:a] = 'A'
|
46
50
|
expect(subject.__size__).to be == 1
|
@@ -55,6 +59,7 @@ describe Tool::ThreadLocal do
|
|
55
59
|
end
|
56
60
|
|
57
61
|
specify 'with dead threads' do
|
62
|
+
next if defined? RUBY_ENGINE and RUBY_ENGINE == 'rbx'
|
58
63
|
subject[:a] = 'A'
|
59
64
|
|
60
65
|
Thread.new do
|
data/tool.gemspec
CHANGED
metadata
CHANGED
@@ -1,71 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tool
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Konstantin Haase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-11-25 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.0.0.beta
|
20
|
-
type: :development
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
24
19
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
26
21
|
version: 3.0.0.beta
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: simplecov
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
22
|
type: :development
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: simplecov
|
35
26
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
-
|
39
|
-
-
|
40
|
-
|
41
|
-
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- &id003
|
30
|
+
- ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
42
36
|
name: coveralls
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
version: '0'
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- *id003
|
48
41
|
type: :development
|
42
|
+
version_requirements: *id004
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
49
45
|
prerelease: false
|
50
|
-
|
51
|
-
requirements:
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
description: general purpose Ruby library used by Sinatra 2.0, Mustermann and related
|
56
|
-
projects
|
46
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- *id003
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id005
|
51
|
+
description: general purpose Ruby library used by Sinatra 2.0, Mustermann and related projects
|
57
52
|
email: konstantin.mailinglists@googlemail.com
|
58
53
|
executables: []
|
54
|
+
|
59
55
|
extensions: []
|
60
|
-
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
61
58
|
- README.md
|
62
|
-
files:
|
59
|
+
files:
|
63
60
|
- .gitignore
|
64
61
|
- .rspec
|
65
62
|
- .travis.yml
|
66
63
|
- Gemfile
|
67
64
|
- LICENSE
|
68
65
|
- README.md
|
66
|
+
- Rakefile
|
69
67
|
- examples/frank.rb
|
70
68
|
- lib/tool/decoration.rb
|
71
69
|
- lib/tool/equality_map.rb
|
@@ -78,30 +76,31 @@ files:
|
|
78
76
|
- spec/thread_local_spec.rb
|
79
77
|
- tool.gemspec
|
80
78
|
homepage: https://github.com/rkh/tool
|
81
|
-
licenses:
|
79
|
+
licenses:
|
82
80
|
- MIT
|
83
81
|
metadata: {}
|
82
|
+
|
84
83
|
post_install_message:
|
85
84
|
rdoc_options: []
|
86
|
-
|
85
|
+
|
86
|
+
require_paths:
|
87
87
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
92
|
version: 2.0.0
|
93
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
-
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- *id003
|
98
96
|
requirements: []
|
97
|
+
|
99
98
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.4
|
101
100
|
signing_key:
|
102
101
|
specification_version: 4
|
103
102
|
summary: general purpose library
|
104
|
-
test_files:
|
103
|
+
test_files:
|
105
104
|
- spec/decoration_spec.rb
|
106
105
|
- spec/equality_map_spec.rb
|
107
106
|
- spec/support/coverage.rb
|