jbuilder 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -0
- data/jbuilder.gemspec +1 -1
- data/lib/jbuilder/jbuilder_template.rb +13 -0
- data/test/jbuilder_template_test.rb +26 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ac0617f83abd9f18566f7abb54b4bfb40f43292
|
4
|
+
data.tar.gz: 81ee411aedba8b8532011a4d02b30a287352aefc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9775756c8e0bceed5f9187629e23c50b11440c6d98f96831c90e0763319b540437d353be56737132a383a15514d1348b032d512448cee6bda4b9c76bae03173c
|
7
|
+
data.tar.gz: d56cca82eb949371a3dc93a4a6e2820de63b58426f9256907473874c46e6448c29dd96479115cd56ba26cff59f9c9a5aa30ae9dd253d47e7991639922c19e306
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
2.0.4
|
4
|
+
-----
|
5
|
+
* [Add cache_if! to conditionally cache JSON fragments](https://github.com/rails/jbuilder/commit/commit/14a5afd8a2c939a6fd710d355a194c114db96eb2)
|
6
|
+
|
3
7
|
2.0.3
|
4
8
|
-----
|
5
9
|
* [Pass options when calling cache_fragment_name](https://github.com/rails/jbuilder/commit/07c2cc7486fe9ef423d7bc821b83f6d485f330e0)
|
data/README.md
CHANGED
@@ -182,6 +182,14 @@ json.cache! ['v1', @person], expires_in: 10.minutes do
|
|
182
182
|
end
|
183
183
|
```
|
184
184
|
|
185
|
+
You can also conditionally cache a block by using `cache_if!` like this:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
json.cache_if! !admin?, ['v1', @person], expires_in: 10.minutes do
|
189
|
+
json.extract! @person, :name, :age
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
185
193
|
Keys can be auto formatted using `key_format!`, this can be used to convert keynames from the standard ruby_format to CamelCase:
|
186
194
|
|
187
195
|
``` ruby
|
data/jbuilder.gemspec
CHANGED
@@ -60,6 +60,19 @@ class JbuilderTemplate < Jbuilder
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# Conditionally catches the json depending in the condition given as first parameter. Has the same
|
64
|
+
# signature as the `cache` helper method in `ActionView::Helpers::CacheHelper` and so can be used in
|
65
|
+
# the same way.
|
66
|
+
#
|
67
|
+
# Example:
|
68
|
+
#
|
69
|
+
# json.cache_if! !admin?, @person, expires_in: 10.minutes do
|
70
|
+
# json.extract! @person, :name, :age
|
71
|
+
# end
|
72
|
+
def cache_if!(condition, *args, &block)
|
73
|
+
condition ? cache!(*args, &block) : yield
|
74
|
+
end
|
75
|
+
|
63
76
|
protected
|
64
77
|
def _handle_partial_options(options)
|
65
78
|
options.reverse_merge! locals: {}
|
@@ -185,6 +185,32 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
185
185
|
assert_equal 'Cache', parsed['name']
|
186
186
|
end
|
187
187
|
|
188
|
+
test 'conditionally fragment caching a JSON object' do
|
189
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
190
|
+
|
191
|
+
render_jbuilder <<-JBUILDER
|
192
|
+
json.cache_if! true, 'cachekey' do
|
193
|
+
json.test1 'Cache'
|
194
|
+
end
|
195
|
+
json.cache_if! false, 'cachekey' do
|
196
|
+
json.test2 'Cache'
|
197
|
+
end
|
198
|
+
JBUILDER
|
199
|
+
|
200
|
+
json = render_jbuilder <<-JBUILDER
|
201
|
+
json.cache_if! true, 'cachekey' do
|
202
|
+
json.test1 'Miss'
|
203
|
+
end
|
204
|
+
json.cache_if! false, 'cachekey' do
|
205
|
+
json.test2 'Miss'
|
206
|
+
end
|
207
|
+
JBUILDER
|
208
|
+
|
209
|
+
parsed = MultiJson.load(json)
|
210
|
+
assert_equal 'Cache', parsed['test1']
|
211
|
+
assert_equal 'Miss', parsed['test2']
|
212
|
+
end
|
213
|
+
|
188
214
|
test 'fragment caching deserializes an array' do
|
189
215
|
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
190
216
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.2.
|
90
|
+
rubygems_version: 2.2.2
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Create JSON structures via a Builder-style DSL
|