johnny_cache 0.0.1
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.
- data/.rvmrc +17 -0
- data/.yardoc/checksums +1 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +2 -0
- data/Gemfile +17 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/doc/JohnnyCache.html +345 -0
- data/doc/JohnnyCache/ClassMethods.html +180 -0
- data/doc/JohnnyCache/MethodCache.html +835 -0
- data/doc/_index.html +127 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +53 -0
- data/doc/css/style.css +320 -0
- data/doc/file_list.html +46 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +127 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +150 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +134 -0
- data/doc/top-level-namespace.html +103 -0
- data/lib/johnny_cache.rb +138 -0
- data/license.txt +0 -0
- data/readme.md +160 -0
- data/spec/johnny_cache/method_cache_spec.rb +37 -0
- data/spec/johnny_cache_spec.rb +55 -0
- data/spec/spec_helper.rb +44 -0
- metadata +225 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe JohnnyCache::MethodCache do
|
5
|
+
before(:all) do
|
6
|
+
@user = User.new
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@uniq ||= 0
|
11
|
+
@uniq += 1
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'initialize' do
|
15
|
+
it 'saves caller' do
|
16
|
+
@user.cache.caller_object.should eq(@user)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'saves cache_method' do
|
20
|
+
cache_method = :fetch
|
21
|
+
@user.cache(cache_method).cache_operation.should eq(cache_method)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'saves options' do
|
25
|
+
options = {:foo => "bar"}
|
26
|
+
@user.cache(options).options.should eq(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'saves options and cache_method' do
|
30
|
+
cache_method = :write
|
31
|
+
options = {:foo => "bar"}
|
32
|
+
cache = @user.cache(cache_method, options)
|
33
|
+
cache.options.should eq(options)
|
34
|
+
cache.cache_operation.should eq(cache_method)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe JohnnyCache do
|
5
|
+
before(:each) do
|
6
|
+
@user = User.new
|
7
|
+
@uniq ||= 0
|
8
|
+
@uniq += 1
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '' do
|
12
|
+
describe 'calling a cached method' do
|
13
|
+
describe 'fetch' do
|
14
|
+
it 'should return the result of the normal method' do
|
15
|
+
@user.cache.foo(@uniq).should == @user.foo(@uniq)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should bypass the normal method if the cache is written' do
|
19
|
+
@user.cache(:write).foo(@uniq)
|
20
|
+
@user.should_not_receive(:foo)
|
21
|
+
@user.cache(:fetch).foo(@uniq)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should bypass the normal method if the cache has been fetched before' do
|
25
|
+
@user.cache(:fetch).foo(@uniq)
|
26
|
+
@user.should_not_receive(:foo)
|
27
|
+
@user.cache(:fetch).foo(@uniq)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should call the normal method if the cache has been not fetched before' do
|
31
|
+
@user.should_receive(:foo)
|
32
|
+
@user.cache(:fetch).foo(@uniq)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should call the normal method if the cache has been not fetched before' do
|
36
|
+
@user.should_receive(:foo)
|
37
|
+
@user.cache.foo(@uniq)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'read' do
|
43
|
+
it 'read should return nil if cache has not been set yet' do
|
44
|
+
@user.cache(:read).foo(@uniq).should eq(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'read should return value if cache has been set' do
|
48
|
+
result = @user.cache.foo(@uniq)
|
49
|
+
@user.cache(:read).foo(@uniq).should eq(result)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../..', 'lib'))
|
6
|
+
|
7
|
+
## Fake rails for testing Rails.cache
|
8
|
+
class Rails
|
9
|
+
def self.cache
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.fetch(key, options, &block)
|
14
|
+
eval("@#{key.gsub(':', '_')} ||= block.call")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.write(key, val, options, &block)
|
18
|
+
eval("@#{key.gsub(':', '_')} = val")
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.read(key, options)
|
22
|
+
eval("@#{key.gsub(':', '_')}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
require 'johnny_cache'
|
28
|
+
class User
|
29
|
+
include JohnnyCache
|
30
|
+
define_keys :foo
|
31
|
+
|
32
|
+
def foo(var=nil)
|
33
|
+
"bar#{var}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
@id ||= rand(100)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
require 'rspec'
|
43
|
+
require 'rspec/autorun'
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: johnny_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Schneems
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-08 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: activesupport
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: keytar
|
46
|
+
prerelease: false
|
47
|
+
type: :runtime
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
version_requirements: *id003
|
59
|
+
name: yard
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
version_requirements: *id004
|
73
|
+
name: rdiscount
|
74
|
+
prerelease: false
|
75
|
+
type: :development
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 49
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 8
|
86
|
+
- 7
|
87
|
+
version: 0.8.7
|
88
|
+
version_requirements: *id005
|
89
|
+
name: rake
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 7
|
99
|
+
segments:
|
100
|
+
- 1
|
101
|
+
- 5
|
102
|
+
- 2
|
103
|
+
version: 1.5.2
|
104
|
+
version_requirements: *id006
|
105
|
+
name: jeweler
|
106
|
+
prerelease: false
|
107
|
+
type: :development
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
version_requirements: *id007
|
119
|
+
name: autotest-standalone
|
120
|
+
prerelease: false
|
121
|
+
type: :development
|
122
|
+
- !ruby/object:Gem::Dependency
|
123
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
version_requirements: *id008
|
133
|
+
name: autotest-growl
|
134
|
+
prerelease: false
|
135
|
+
type: :development
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
version_requirements: *id009
|
147
|
+
name: rspec
|
148
|
+
prerelease: false
|
149
|
+
type: :development
|
150
|
+
description: "\n \"I've Been Everywhere\" and I'm tired of writing cache wrappers \"One Piece at a Time\" for methods. So if you no longer want to \"Walk the Line\" then JohnnyCache can help to easily cache your ruby methods. Use this Gem or else you'll get thrown into the \"Ring of Fire\".\n "
|
151
|
+
email: richard.schneeman@gmail.com
|
152
|
+
executables: []
|
153
|
+
|
154
|
+
extensions: []
|
155
|
+
|
156
|
+
extra_rdoc_files: []
|
157
|
+
|
158
|
+
files:
|
159
|
+
- .rvmrc
|
160
|
+
- .yardoc/checksums
|
161
|
+
- .yardoc/objects/root.dat
|
162
|
+
- .yardoc/proxy_types
|
163
|
+
- Gemfile
|
164
|
+
- Rakefile
|
165
|
+
- VERSION
|
166
|
+
- autotest/discover.rb
|
167
|
+
- doc/JohnnyCache.html
|
168
|
+
- doc/JohnnyCache/ClassMethods.html
|
169
|
+
- doc/JohnnyCache/MethodCache.html
|
170
|
+
- doc/_index.html
|
171
|
+
- doc/class_list.html
|
172
|
+
- doc/css/common.css
|
173
|
+
- doc/css/full_list.css
|
174
|
+
- doc/css/style.css
|
175
|
+
- doc/file_list.html
|
176
|
+
- doc/frames.html
|
177
|
+
- doc/index.html
|
178
|
+
- doc/js/app.js
|
179
|
+
- doc/js/full_list.js
|
180
|
+
- doc/js/jquery.js
|
181
|
+
- doc/method_list.html
|
182
|
+
- doc/top-level-namespace.html
|
183
|
+
- lib/johnny_cache.rb
|
184
|
+
- license.txt
|
185
|
+
- readme.md
|
186
|
+
- spec/johnny_cache/method_cache_spec.rb
|
187
|
+
- spec/johnny_cache_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
homepage: http://github.com/Schnems/johnny_cache
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
none: false
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
hash: 3
|
203
|
+
segments:
|
204
|
+
- 0
|
205
|
+
version: "0"
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
hash: 3
|
212
|
+
segments:
|
213
|
+
- 0
|
214
|
+
version: "0"
|
215
|
+
requirements: []
|
216
|
+
|
217
|
+
rubyforge_project:
|
218
|
+
rubygems_version: 1.8.6
|
219
|
+
signing_key:
|
220
|
+
specification_version: 3
|
221
|
+
summary: Cache methods quickly and easily.
|
222
|
+
test_files:
|
223
|
+
- spec/johnny_cache/method_cache_spec.rb
|
224
|
+
- spec/johnny_cache_spec.rb
|
225
|
+
- spec/spec_helper.rb
|