tool 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 957f199ec72715506547dd26a5d290743e92b6de
4
- data.tar.gz: 2d398cd3454dffa91ff9d7d2a80f44405be6c197
5
- SHA512:
6
- metadata.gz: cfecff9484e4eda3240e1b99395e00683c583c09f0b1e9dc5c533347e422d37204aa3113204c4d804f4d8fa78cc6c5f19756a8e12dca4f7cb59aed047794c38a
7
- data.tar.gz: 077654427a1d76b1a889641125aac6b4b6aeb9338fe1cb215f30d8d8ec077b3e07912d7d0570f09482539ad5247e38018584030eac8f3b872387e99175ceaa98
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91786fb78ed736327ffe723e946be2fd67267a73
4
+ data.tar.gz: 22ebe6e6931dab1c0c2d6ace6030875f71512622
5
+ SHA512:
6
+ metadata.gz: ae28a3fc4f351498e3f776c931405caa0b69edcadcd7a87fce4c0a0c7284192f18ca27d9bbb172b821b8b0a0f2d17342baa890ca280fe494f3111c31bb97d378
7
+ data.tar.gz: e6f9b32b4ff5564f99346817ff4ca298ce557c171c55cdc4c0a18dddcd78898b927ba2ea695171b6c3e3b964bc3d9e4a3594205ab79f3849486ad20e4650b867
@@ -1,2 +1,6 @@
1
- rvm: [2.0.0, 2.1.0]
2
- script: bundle exec rspec
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.1
6
+ - rbx-2.3.0
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
- General purpose Ruby library used by Sinatra 2.0, Mustermann and related projects.
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
- Included:
5
+ ## Tool::Decoration
6
6
 
7
- * **Decoration** - Mixin for easy method decorations.
8
- * **EqualityMap** - Weak reference caching based on key equality.
9
- * **ThreadLocal** - True thread locals that are properly garbage collected.
10
- * **WarningFilter** - Enable Ruby's warnings, but filter out those caused by third party gems.
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
+ ```
@@ -0,0 +1,4 @@
1
+ desc "Run specs"
2
+ task(:spec) { ruby '-S rspec spec -c -w' }
3
+ task(:test => :spec)
4
+ task(:default => :spec)
@@ -17,6 +17,10 @@ module Tool
17
17
  class EqualityMap
18
18
  attr_reader :map
19
19
 
20
+ def self.new
21
+ defined?(ObjectSpace::WeakMap) ? super : {}
22
+ end
23
+
20
24
  def initialize
21
25
  @keys = {}
22
26
  @map = ObjectSpace::WeakMap.new
@@ -1,3 +1,3 @@
1
1
  module Tool
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -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" }
@@ -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
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'rspec', '~> 3.0.0.beta'
20
20
  s.add_development_dependency 'simplecov'
21
21
  s.add_development_dependency 'coveralls'
22
+ s.add_development_dependency "rake"
22
23
  end
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.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
- date: 2014-02-23 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
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
- version_requirements: !ruby/object:Gem::Requirement
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
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
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
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
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
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
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
- extra_rdoc_files:
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
- require_paths:
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.2.0
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