rabl-rails 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/rabl-rails/library.rb +12 -6
- data/lib/rabl-rails/version.rb +1 -1
- data/test/test_library.rb +11 -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: 3ecb1329a32490a735d1554c309c4d22b7a4eecf
|
4
|
+
data.tar.gz: 19958bd42ebd7ef7ff2e3f6d961c034c9409f17d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 981a64007d589ba27a1b2ce4f85cd63763dc6335fc9d96ddd5df71178002c3648a44f6cbff7a0d7ad4fc1639b478278263898829f940ee002a645099c45ef3c3
|
7
|
+
data.tar.gz: ab7d0fd23fe2fcce56ac0ad149629e89d2125e3ee55f8fa0e97e0fda435012f728a73c63cdf0c156913eefa1d8a82fbe3cd0b030c83238d04cf4ca9a5ee9ee0d
|
data/CHANGELOG.md
CHANGED
data/lib/rabl-rails/library.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'singleton'
|
2
|
-
require '
|
2
|
+
require 'monitor'
|
3
3
|
|
4
4
|
module RablRails
|
5
5
|
class Library
|
@@ -15,11 +15,12 @@ module RablRails
|
|
15
15
|
}.freeze
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
@cached_templates =
|
18
|
+
@cached_templates = {}
|
19
|
+
@monitor = Monitor.new
|
19
20
|
end
|
20
21
|
|
21
22
|
def reset_cache!
|
22
|
-
@cached_templates =
|
23
|
+
@cached_templates = {}
|
23
24
|
end
|
24
25
|
|
25
26
|
def get_rendered_template(source, view, locals = nil)
|
@@ -50,9 +51,14 @@ module RablRails
|
|
50
51
|
private
|
51
52
|
|
52
53
|
def synchronized_compile(path, source, view)
|
53
|
-
@cached_templates
|
54
|
-
|
55
|
-
|
54
|
+
@cached_templates[path] || @monitor.synchronize do
|
55
|
+
# Any thread holding this lock will be compiling the template needed
|
56
|
+
# by the threads waiting. So re-check the template presence to avoid
|
57
|
+
# re-compilation
|
58
|
+
@cached_templates.fetch(path) do
|
59
|
+
source ||= fetch_source(path, view)
|
60
|
+
@cached_templates[path] = compile(source, view)
|
61
|
+
end
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
data/lib/rabl-rails/version.rb
CHANGED
data/test/test_library.rb
CHANGED
@@ -68,6 +68,17 @@ class TestLibrary < Minitest::Test
|
|
68
68
|
|
69
69
|
assert_empty @library.cached_templates
|
70
70
|
end
|
71
|
+
|
72
|
+
it 'caches multiple templates in one compilation' do
|
73
|
+
@context.virtual_path = 'users/show'
|
74
|
+
with_configuration :cache_templates, true do
|
75
|
+
@library.stub :fetch_source, 'attributes :id' do
|
76
|
+
@library.compile_template_from_source("child(:account, partial: 'users/_account')", @context)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal 2, @library.cached_templates.size
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Cocchi-Perrier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.11
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Fast Rails 4+ templating system with JSON, XML and PList support
|