curlybars 1.3.0 → 1.3.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
  SHA256:
3
- metadata.gz: 3c5f1fe84620e10957d38e663d3883158c00b6db25395c61e9628ddd3d19d110
4
- data.tar.gz: 5eac82875ef4fca6a4c0aa728626615c643089ed6cc24de91232d793753f8f5b
3
+ metadata.gz: f83af0f1fc951b9a35dd68ae1b3bd181799031cf37913100574c65d98de5e870
4
+ data.tar.gz: 954af845f827c80b1fced94ad10ed5f1bcaf99dc872f3b54435ab9e23c3d82e3
5
5
  SHA512:
6
- metadata.gz: 3697082fceb22d1d868d4de0fcf1054d8facc0e8dee7da0e58704bf34bb303a0cd287b460baa5d40ffcbf17ed7d0e3235643b7d855e57f821ed63223f1d737e3
7
- data.tar.gz: dfba149b55705dbc9567a763dbc12b3514296a43ec576a683642f83f727d6d7ec4c49ffc514a4c2a9a4d1ec91740365dd144d2a87bde96d59b2632b8c24ed4df
6
+ metadata.gz: f75d2a62e3c4dec26b01bf04928d624e70a0b807cf99c40ac0b5b6a03e421e5f296f6a5eaed609bb7bd4679bbe402ebfd0e8626c6f2527a8118afd71aa937522
7
+ data.tar.gz: 748d32d09437bdf7bd02b5d607aee846cabd02ab015a837ec95ccc00e451099f21cf71f3b5a7cb305e8d4f8bfe18145b7401531db55cb8ba4fc0ad66906e259e
@@ -14,19 +14,21 @@ module Curlybars
14
14
  methods_with_type_validator.call(methods_with_type)
15
15
 
16
16
  define_method(:allowed_methods) do
17
- methods_list = methods_without_type + methods_with_type.keys
17
+ @method_whitelist_allowed_methods ||= begin
18
+ methods_list = methods_without_type + methods_with_type.keys
18
19
 
19
- # Adds methods to the list of allowed methods
20
- method_adder = lambda do |*more_methods, **more_methods_with_type|
21
- methods_with_type_validator.call(more_methods_with_type)
20
+ # Adds methods to the list of allowed methods
21
+ method_adder = lambda do |*more_methods, **more_methods_with_type|
22
+ methods_with_type_validator.call(more_methods_with_type)
22
23
 
23
- methods_list += more_methods
24
- methods_list += more_methods_with_type.keys
25
- end
24
+ methods_list += more_methods
25
+ methods_list += more_methods_with_type.keys
26
+ end
26
27
 
27
- contextual_block&.call(self, method_adder)
28
+ contextual_block&.call(self, method_adder)
28
29
 
29
- defined?(super) ? super() + methods_list : methods_list
30
+ defined?(super) ? super() + methods_list : methods_list
31
+ end
30
32
  end
31
33
 
32
34
  define_singleton_method(:methods_schema) do |context = nil|
@@ -1,3 +1,3 @@
1
1
  module Curlybars
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.3.1'.freeze
3
3
  end
@@ -16,6 +16,8 @@ describe Curlybars::MethodWhitelist do
16
16
 
17
17
  let(:validation_context_class) do
18
18
  Class.new do
19
+ attr_accessor :invocation_count
20
+
19
21
  def foo?
20
22
  true
21
23
  end
@@ -130,10 +132,15 @@ describe Curlybars::MethodWhitelist do
130
132
 
131
133
  Class.new do
132
134
  extend Curlybars::MethodWhitelist
135
+ attr_accessor :invocation_count
136
+
133
137
  allow_methods :cook, link: LinkPresenter do |context, allow_method|
134
138
  if context.foo?
135
139
  allow_method.call(:bar)
136
140
  end
141
+
142
+ context.invocation_count ||= 0
143
+ context.invocation_count += 1
137
144
  end
138
145
 
139
146
  def foo?
@@ -173,6 +180,14 @@ describe Curlybars::MethodWhitelist do
173
180
  expect(post_presenter.new.allowed_methods).to eq([:cook, :link, :bar, :form, :foo_bar, :wave])
174
181
  end
175
182
 
183
+ it "only invokes the context block once" do
184
+ presenter = post_presenter.new
185
+
186
+ 10.times { presenter.allowed_methods }
187
+
188
+ expect(presenter.invocation_count).to eq(1)
189
+ end
190
+
176
191
  it "returns a dependency_tree with inheritance and composition with context" do
177
192
  expect(post_presenter.dependency_tree(validation_context_class.new)).
178
193
  to eq(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curlybars
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Libo Cannici
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-12-17 00:00:00.000000000 Z
16
+ date: 2020-01-13 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: actionpack