cells 3.6.4 → 3.6.5
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/CHANGES.textile +9 -0
- data/lib/cell.rb +6 -2
- data/lib/cell/caching.rb +29 -7
- data/lib/cell/test_case.rb +1 -1
- data/lib/cells/version.rb +1 -1
- data/test/app/cells/bassist/shout.html.erb +1 -0
- data/test/app/cells/bassist_cell.rb +6 -1
- data/test/rails/caching_test.rb +23 -0
- data/test/test_case_test.rb +4 -0
- metadata +4 -3
data/CHANGES.textile
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
h2. 3.6.5
|
2
|
+
|
3
|
+
h3. Bugfixes
|
4
|
+
* `Cell::TestCase#invoke` now properly accepts state-args.
|
5
|
+
|
6
|
+
h3. Changes
|
7
|
+
* Added the `:if` option to `Base.cache` which allows adding a conditional proc or instance method to the cache definition. If it doesn't return true, caching for that state is skipped.
|
8
|
+
|
9
|
+
|
1
10
|
h2. 3.6.4
|
2
11
|
|
3
12
|
h3. Bugfixes
|
data/lib/cell.rb
CHANGED
@@ -18,8 +18,7 @@ module Cell
|
|
18
18
|
cell = create_cell_for(controller, name, *args) # DISCUSS: we always save options.
|
19
19
|
yield cell if block_given?
|
20
20
|
|
21
|
-
|
22
|
-
cell.render_state(state) # backward-compat.
|
21
|
+
cell.render_state_with_args(state, *args)
|
23
22
|
end
|
24
23
|
|
25
24
|
# Creates a cell instance. Note that this method calls builders which were attached to the
|
@@ -77,6 +76,11 @@ module Cell
|
|
77
76
|
end
|
78
77
|
|
79
78
|
module InstanceMethods
|
79
|
+
def render_state_with_args(state, *args) # TODO: remove me in 4.0.
|
80
|
+
return render_state(state, *args) if state_accepts_args?(state)
|
81
|
+
render_state(state) # backward-compat.
|
82
|
+
end
|
83
|
+
|
80
84
|
def state_accepts_args?(state)
|
81
85
|
method(state).arity != 0
|
82
86
|
end
|
data/lib/cell/caching.rb
CHANGED
@@ -19,6 +19,11 @@ module Cell
|
|
19
19
|
#
|
20
20
|
# cache :show, :expires_in => 10.minutes
|
21
21
|
#
|
22
|
+
# The +:if+ option lets you define a conditional proc or instance method. If it doesn't
|
23
|
+
# return a true value, caching for that state is skipped.
|
24
|
+
#
|
25
|
+
# cache :show, :if => proc { |cell, options| options[:enable_cache] }
|
26
|
+
#
|
22
27
|
# If you need your own granular cache keys, pass a versioner block.
|
23
28
|
#
|
24
29
|
# cache :show do |cell, options|
|
@@ -40,14 +45,19 @@ module Cell
|
|
40
45
|
def cache(state, *args, &block)
|
41
46
|
options = args.extract_options!
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
conditional_procs[state] = options.delete(:if)
|
49
|
+
version_procs[state] = args.first || block
|
50
|
+
cache_options[state] = options
|
45
51
|
end
|
46
52
|
|
47
53
|
def version_procs
|
48
54
|
@version_procs ||= {}
|
49
55
|
end
|
50
56
|
|
57
|
+
def conditional_procs
|
58
|
+
@conditional_procs ||= {}
|
59
|
+
end
|
60
|
+
|
51
61
|
def cache_options
|
52
62
|
@cache_options ||= {}
|
53
63
|
end
|
@@ -85,7 +95,7 @@ module Cell
|
|
85
95
|
end
|
86
96
|
|
87
97
|
def render_state(state, *args)
|
88
|
-
return super(state, *args) unless
|
98
|
+
return super(state, *args) unless cache?(state, *args)
|
89
99
|
|
90
100
|
key = self.class.state_cache_key(state, call_state_versioner(state, *args))
|
91
101
|
options = self.class.cache_options[state]
|
@@ -95,12 +105,24 @@ module Cell
|
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
108
|
+
def cache?(state, *args)
|
109
|
+
self.class.cache?(state) and call_state_conditional(state, *args)
|
110
|
+
end
|
111
|
+
|
98
112
|
protected
|
113
|
+
def call_proc_or_method(state, method, *args)
|
114
|
+
return method.call(self, *args) if method.kind_of?(Proc)
|
115
|
+
state_accepts_args?(state) ? send(method, *args) : send(method)
|
116
|
+
end
|
117
|
+
|
99
118
|
def call_state_versioner(state, *args)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
119
|
+
method = self.class.version_procs[state] or return
|
120
|
+
call_proc_or_method(state, method, *args)
|
121
|
+
end
|
122
|
+
|
123
|
+
def call_state_conditional(state, *args)
|
124
|
+
method = self.class.conditional_procs[state] or return true
|
125
|
+
call_proc_or_method(state, method, *args)
|
104
126
|
end
|
105
127
|
|
106
128
|
end
|
data/lib/cell/test_case.rb
CHANGED
@@ -124,7 +124,7 @@ module Cell
|
|
124
124
|
attr_reader :last_invoke
|
125
125
|
|
126
126
|
def invoke(state, *args)
|
127
|
-
@last_invoke = self.class.controller_class.new(@controller, *args).
|
127
|
+
@last_invoke = self.class.controller_class.new(@controller, *args).render_state_with_args(state, *args)
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
data/lib/cells/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
*shouts* <%= @words %>
|
data/test/rails/caching_test.rb
CHANGED
@@ -283,5 +283,28 @@ class CachingFunctionalTest < ActiveSupport::TestCase
|
|
283
283
|
assert_equal "1", render_cell(:director, :count, 3)
|
284
284
|
assert_equal "2", render_cell(:director, :count, 4)
|
285
285
|
end
|
286
|
+
|
287
|
+
should "be able to use caching conditionally" do
|
288
|
+
@class.cache :count, :if => proc { |cell, int| (int % 2) != 0 }
|
289
|
+
|
290
|
+
assert_equal "1", render_cell(:director, :count, 1)
|
291
|
+
assert_equal "2", render_cell(:director, :count, 2)
|
292
|
+
assert_equal "1", render_cell(:director, :count, 3)
|
293
|
+
assert_equal "4", render_cell(:director, :count, 4)
|
294
|
+
end
|
295
|
+
|
296
|
+
should "cache conditionally with an instance method" do
|
297
|
+
@class.cache :count, :if => :odd?
|
298
|
+
@class.class_eval do
|
299
|
+
def odd?(int)
|
300
|
+
(int % 2) != 0
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
assert_equal "1", render_cell(:director, :count, 1)
|
305
|
+
assert_equal "2", render_cell(:director, :count, 2)
|
306
|
+
assert_equal "1", render_cell(:director, :count, 3)
|
307
|
+
assert_equal "4", render_cell(:director, :count, 4)
|
308
|
+
end
|
286
309
|
end
|
287
310
|
end
|
data/test/test_case_test.rb
CHANGED
@@ -67,6 +67,10 @@ class TestCaseTest < Cell::TestCase
|
|
67
67
|
#assert_equal "Doo", invoke(:play)
|
68
68
|
end
|
69
69
|
|
70
|
+
should "provide #invoke accepting args" do
|
71
|
+
assert_equal "*shouts* Listen!\n", invoke(:shout, :words => "Listen!")
|
72
|
+
end
|
73
|
+
|
70
74
|
should "provide assert_select" do
|
71
75
|
invoke :promote
|
72
76
|
assert_select "a", "vd.com"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 3.6.
|
8
|
+
- 5
|
9
|
+
version: 3.6.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nick Sutterer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-08-15 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- test/app/cells/bassist/pose.html.erb
|
140
140
|
- test/app/cells/bassist/promote.html.erb
|
141
141
|
- test/app/cells/bassist/provoke.html.erb
|
142
|
+
- test/app/cells/bassist/shout.html.erb
|
142
143
|
- test/app/cells/bassist/sing.html.haml
|
143
144
|
- test/app/cells/bassist/slap.html.erb
|
144
145
|
- test/app/cells/bassist/yell.en.html.erb
|