rabl-rails 0.5.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de487a654a879918209db30bfb6d384b26e8bc0e
4
- data.tar.gz: 54e73001a009a25491238d246da5e0a09b79d66f
3
+ metadata.gz: 3ecb1329a32490a735d1554c309c4d22b7a4eecf
4
+ data.tar.gz: 19958bd42ebd7ef7ff2e3f6d961c034c9409f17d
5
5
  SHA512:
6
- metadata.gz: 21fdf8c8e8f80b1d6807dc0f082e3db64b29c24329010c63f4979245bbe10752c8122f527728311113befde3f766a2e981639473d879d7888d584e53dc70a24c
7
- data.tar.gz: 26511a368b88f055e7c9f8a63253239be920714f1d19740ac82cc060899f5aa8686fbf51062be76c1c8819d8ac7139350809a76f5c2e09b83718c7e8ba37220a
6
+ metadata.gz: 981a64007d589ba27a1b2ce4f85cd63763dc6335fc9d96ddd5df71178002c3648a44f6cbff7a0d7ad4fc1639b478278263898829f940ee002a645099c45ef3c3
7
+ data.tar.gz: ab7d0fd23fe2fcce56ac0ad149629e89d2125e3ee55f8fa0e97e0fda435012f728a73c63cdf0c156913eefa1d8a82fbe3cd0b030c83238d04cf4ca9a5ee9ee0d
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.1
4
+ * Fix bug when trying to compile partials with caching enabled
5
+
3
6
  ## 0.5.0
4
7
  * Add requirement ruby >= 2.2
5
8
  * Drop support for Rails < 4.2
@@ -1,5 +1,5 @@
1
1
  require 'singleton'
2
- require 'concurrent/map'
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 = Concurrent::Map.new
18
+ @cached_templates = {}
19
+ @monitor = Monitor.new
19
20
  end
20
21
 
21
22
  def reset_cache!
22
- @cached_templates = Concurrent::Map.new
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.compute_if_absent(path) do
54
- source ||= fetch_source(path, view)
55
- compile(source, view)
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
 
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -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.0
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-02 00:00:00.000000000 Z
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.4.5.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