dcache 0.0.0

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.
@@ -0,0 +1,171 @@
1
+ require "dcache"
2
+
3
+ share_examples_for "base DCache" do
4
+ it "should retrieve 'value'" do
5
+ c.add :key, "value"
6
+ c.get(:key).should == "value"
7
+ end
8
+
9
+ it "bunch retrieve simple" do
10
+ (1..500).each do |i|
11
+ c.add :"key#{i}", "value#{i}"
12
+ c.get(:"key#{i}").should == "value#{i}"
13
+ end
14
+ end
15
+
16
+ it "bunch retrieve delayed" do
17
+ (1..500).each do |i|
18
+ c.add :"key#{i}", "value#{i}"
19
+ end
20
+ (100..300).each do |i|
21
+ c.get(:"key#{i}").should == "value#{i}"
22
+ end
23
+ end
24
+
25
+ it "should retrieve nil" do
26
+ c.get(:foo).should be_nil
27
+ end
28
+
29
+ it "should retrieve 123" do
30
+ c.get(:foo, 123).should == 123
31
+ end
32
+
33
+ it "should execute" do
34
+ executed = false
35
+ c.get(:foo) do
36
+ executed = true
37
+ :ok
38
+ end.should == :ok
39
+ executed.should be_true
40
+ end
41
+
42
+ it "should add value" do
43
+ c.get_or_add(:key, "value").should == "value"
44
+ c.get(:key).should == "value"
45
+ end
46
+
47
+ it "should add value from block" do
48
+ c.get_or_add(:key) { "value" }.should == "value"
49
+ c.get(:key).should == "value"
50
+ end
51
+
52
+ it "should raise an exception" do
53
+ lambda { c.get_or_raise(:foo) }.should raise_error(ArgumentError)
54
+ end
55
+
56
+ it "should remove a key" do
57
+ [:a, :b, :c].each { |i| c.add i, "value" }
58
+ c.delete(:b).should be_nil
59
+ c.get(:b).should be_nil
60
+ [:a, :c].each { |i| c.get(i).should == "value" }
61
+ end
62
+
63
+ it "should erase cache" do
64
+ [:a, :b, :c].each { |i| c.add i, "value" }
65
+ c.clear
66
+ [:a, :b, :c].each { |i| c.get(i).should be_nil }
67
+ end
68
+
69
+ it "should create a hash" do
70
+ hash = { :a => "value", :b => 42, :c => nil }
71
+ hash.each { |k,v| c.add k, v }
72
+ c.to_hash.should == hash
73
+ end
74
+
75
+ it "should time out immediately" do
76
+ c.add :key, "value", -1
77
+ c.get(:key).should be_nil
78
+ end
79
+
80
+ it "should time out" do
81
+ c.add :key, "value", 1
82
+ sleep 1
83
+ c.get(:key).should be_nil
84
+ end
85
+
86
+ it "hits should be 0" do
87
+ c.get :foo
88
+ c.hits.should == 0
89
+ end
90
+
91
+ it "hits should be 1" do
92
+ c.add :key, 3
93
+ c.get :key
94
+ c.hits.should == 1
95
+ end
96
+
97
+ it "misses should be 0" do
98
+ c.add :key, 3
99
+ c.get :key
100
+ c.misses.should == 0
101
+ end
102
+
103
+ it "misses should be 1" do
104
+ c.get :foo
105
+ c.misses.should == 1
106
+ end
107
+
108
+ it "'s lenght should be 0" do
109
+ c.length.should == 0
110
+ end
111
+
112
+ it "'s length should be 1" do
113
+ c.add :key, 1
114
+ c.length.should == 1
115
+ end
116
+
117
+ it "'s length should be 1000" do
118
+ (1..1100).each { |i| c.add :"key#{i}", i }
119
+ c.length.should == 1000
120
+ c.to_hash.size.should == 1000
121
+ end
122
+
123
+ end
124
+
125
+ ##############################################################################
126
+ # Specific tests below
127
+
128
+ describe "DCache(:ary)" do
129
+ let(:c) { DCache.new :ary, 1000 }
130
+ it_should_behave_like "base DCache"
131
+ end
132
+
133
+ describe "DCache(:list)" do
134
+ let(:c) { DCache.new :list, 1000 }
135
+ it_should_behave_like "base DCache"
136
+
137
+ it "stored should be 0" do
138
+ c.stored.should == 0
139
+ end
140
+
141
+ it "stored should be 1" do
142
+ c.add :key, 3
143
+ c.stored.should == 1
144
+ end
145
+
146
+ it "removes should be 0" do
147
+ c.removed.should == 0
148
+ end
149
+
150
+ it "removed should be 1" do
151
+ c.add :key, 3
152
+ c.clear
153
+ c.removed.should == 1
154
+ end
155
+ it "removed should be 1" do
156
+ c.add :key, 3
157
+ c.remove :key
158
+ c.removed.should == 1
159
+ end
160
+
161
+ it "should remove excess items" do
162
+ (1..10).each { |i| c.add i, :a }
163
+ a = [ 2, 8, 9, 1, 5, 10, 4, 3, 7, 6 ]
164
+ a.each { |i| c.get i }
165
+ (c.max_items = 5).should == 5
166
+ c.max_items.should == 5
167
+ c.length.should == 5
168
+ a[0..4].each { |i| c.get(i).should be_nil }
169
+ a[5..9].each { |i| c.get(i).should == :a }
170
+ end
171
+ end
data/yard/reader.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'yard'
2
+
3
+ # Class to process <tt>embedded_reader :foo</tt> constructs
4
+ class YARD::Handlers::Ruby::ParameterHandler < YARD::Handlers::Ruby::Base
5
+
6
+ handles method_call(:embedded_reader)
7
+
8
+ def process
9
+
10
+ statement.parameters.each do |p|
11
+ break unless p
12
+ name = case p.type
13
+ when :symbol_literal
14
+ p.jump(:ident, :op, :kw, :const).source
15
+ when :string_literal
16
+ p.jump(:string_content).source
17
+ else
18
+ raise YARD::Parser::UndocumentableError, p.type.to_s
19
+ end
20
+
21
+ a = namespace.attributes[scope][name] = SymbolHash[:read => nil]
22
+ a[:read] = MethodObject.new(namespace, name, scope) do |o|
23
+ o.visibility = :public
24
+ o.signature = "def #{name}"
25
+ o.source = "def #{name}\n @backend.#{name}\nend"
26
+ o.explicit = false
27
+ end
28
+ register a[:read]
29
+
30
+ end
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "K\xC5\x91v\xC3\xA1g\xC3\xB3, Zolt\xC3\xA1n"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-29 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.2"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe-git
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: yard
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0.5"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.4.0
54
+ version:
55
+ description: A simple caching gem.
56
+ email:
57
+ - DirtY.iCE.hu@gmail.com
58
+ executables: []
59
+
60
+ extensions:
61
+ - ext/dcache_ary/extconf.rb
62
+ - ext/dcache_list/extconf.rb
63
+ extra_rdoc_files:
64
+ - Manifest.txt
65
+ files:
66
+ - .autotest
67
+ - .yardopts
68
+ - History.rdoc
69
+ - Manifest.txt
70
+ - README.rdoc
71
+ - Rakefile
72
+ - ext/dcache_ary/dcache_ary.c
73
+ - ext/dcache_ary/extconf.rb
74
+ - ext/dcache_list/dcache_list.c
75
+ - ext/dcache_list/extconf.rb
76
+ - lib/dcache.rb
77
+ - spec/dcache_spec.rb
78
+ - yard/reader.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/DirtYiCE/DCache
81
+ licenses: []
82
+
83
+ post_install_message: "** Please build documentation with `yard'"
84
+ rdoc_options:
85
+ - --main
86
+ - README.rdoc
87
+ require_paths:
88
+ - lib
89
+ - ext
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project: dcache
105
+ rubygems_version: 1.3.5
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple caching gem.
109
+ test_files: []
110
+