erector_cache 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/erector_cache/widget.rb +12 -1
- data/spec/erector_cache/widget_spec.rb +49 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/erector_cache/widget.rb
CHANGED
@@ -5,6 +5,7 @@ module ErectorCache
|
|
5
5
|
cattr_accessor :expire_in
|
6
6
|
extend ClassMethods
|
7
7
|
class_inheritable_array :key_components
|
8
|
+
class_inheritable_hash :interpolations
|
8
9
|
include InstanceMethods
|
9
10
|
alias_method_chain :_render_via, :caching
|
10
11
|
end
|
@@ -15,6 +16,10 @@ module ErectorCache
|
|
15
16
|
self.key_components = components
|
16
17
|
end
|
17
18
|
|
19
|
+
def interpolate(interpolations)
|
20
|
+
self.interpolations = interpolations
|
21
|
+
end
|
22
|
+
|
18
23
|
def cache_for(ttl)
|
19
24
|
self.expire_in = ttl
|
20
25
|
end
|
@@ -54,7 +59,6 @@ module ErectorCache
|
|
54
59
|
collection << [key, value]
|
55
60
|
end.flatten.join(":")
|
56
61
|
end
|
57
|
-
|
58
62
|
end
|
59
63
|
|
60
64
|
module InstanceMethods
|
@@ -72,6 +76,13 @@ module ErectorCache
|
|
72
76
|
_render_via_without_caching(parent, options)
|
73
77
|
else
|
74
78
|
options = {:expire_in => @expire_in || 1.hour, :raw => true}
|
79
|
+
unless self.class.interpolations.blank?
|
80
|
+
options[:interpolate] = self.class.interpolations.inject({}) do |collection, interpolation|
|
81
|
+
collection[interpolation.first] = self.instance_variable_get("@#{interpolation.last}")
|
82
|
+
collection
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
75
86
|
cached_fragment = LAWNCHAIR.cache(cache_key, options) do
|
76
87
|
parent.capture { _render_via_without_caching(parent, options) }
|
77
88
|
end
|
@@ -47,6 +47,26 @@ class NinjaTurtle < Turtle
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
class InterpolatedTurtle < Turtle
|
51
|
+
def content
|
52
|
+
div "Cool stuff below"
|
53
|
+
widget InterpolatedNinjaTurtle, :name => @name, :weapon => @weapon, :master => @master, :pizzas_eaten => @pizzas_eaten
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class InterpolatedNinjaTurtle < NinjaTurtle
|
58
|
+
cache_with :weapon, :master => lambda {|m| m.name }
|
59
|
+
cache_for 25.years
|
60
|
+
interpolate "PIZZAS_EATEN" => :pizzas_eaten
|
61
|
+
|
62
|
+
def content
|
63
|
+
span "Weapon: #{@weapon}"
|
64
|
+
span "Cached at: #{Time.now.to_s(:db)}"
|
65
|
+
span "Eaten: PIZZAS_EATEN pizzas"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
50
70
|
describe ErectorCache::Widget do
|
51
71
|
before do
|
52
72
|
@splinter = Master.new("Splinter")
|
@@ -168,6 +188,35 @@ describe ErectorCache::Widget do
|
|
168
188
|
|
169
189
|
@output.should include("Cached at: #{expected_cached_at_time}")
|
170
190
|
end
|
191
|
+
|
192
|
+
context "when there are content interpolations set" do
|
193
|
+
before do
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
it "displays the appropriate content" do
|
198
|
+
expected_cached_at_time = Time.now.to_s(:db)
|
199
|
+
|
200
|
+
render_template do |controller|
|
201
|
+
controller.render_widget InterpolatedTurtle, :name => "Leonardo", :weapon => "Dual Katanas", :master => @splinter, :pizzas_eaten => "under 3000"
|
202
|
+
end
|
203
|
+
|
204
|
+
@output.should include("Weapon: Dual Katanas")
|
205
|
+
@output.should include("under 3000")
|
206
|
+
@output.should include("Cached at: #{expected_cached_at_time}")
|
207
|
+
|
208
|
+
|
209
|
+
sleep 1
|
210
|
+
|
211
|
+
render_template do |controller|
|
212
|
+
controller.render_widget InterpolatedTurtle, :name => "Leonardo", :weapon => "Dual Katanas", :master => @splinter, :pizzas_eaten => "over 9000"
|
213
|
+
end
|
214
|
+
|
215
|
+
@output.should include("Cached at: #{expected_cached_at_time}")
|
216
|
+
@output.should_not include("under 3000")
|
217
|
+
@output.should include("over 9000")
|
218
|
+
end
|
219
|
+
end
|
171
220
|
end
|
172
221
|
|
173
222
|
context "when there is NO cache_with set" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erector_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grockit
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-18 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|