curlybars 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/curlybars/method_whitelist.rb +11 -9
- data/lib/curlybars/version.rb +1 -1
- data/spec/curlybars/method_whitelist_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83af0f1fc951b9a35dd68ae1b3bd181799031cf37913100574c65d98de5e870
|
4
|
+
data.tar.gz: 954af845f827c80b1fced94ad10ed5f1bcaf99dc872f3b54435ab9e23c3d82e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
17
|
+
@method_whitelist_allowed_methods ||= begin
|
18
|
+
methods_list = methods_without_type + methods_with_type.keys
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
24
|
+
methods_list += more_methods
|
25
|
+
methods_list += more_methods_with_type.keys
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
contextual_block&.call(self, method_adder)
|
28
29
|
|
29
|
-
|
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|
|
data/lib/curlybars/version.rb
CHANGED
@@ -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.
|
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:
|
16
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: actionpack
|