proxy_method 1.1.2 → 1.2.0
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 +4 -4
- data/README.md +2 -2
- data/lib/proxy_method/version.rb +1 -1
- data/lib/proxy_method.rb +16 -4
- data/test/samples/animal/listy_leopard.rb +6 -0
- data/test/test_proxy_method.rb +29 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef91930d4c8a5e2d43758850268ca220dc537462e397701ac509a2df2ded4c91
|
4
|
+
data.tar.gz: 982c71256adcc6d6200b73d962ee086d82e5b44118a026b602b88d276a3316d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b583e9ad496614fba88c1e18bdc00b5a211d516602b2a3da77311b7e57479b4f95d1226021fe7c2d6a8d5296398af9897fcc5e7335d2fa7d104bb4f64fc78295
|
7
|
+
data.tar.gz: 7a9677e0faac50aa8cb9a3a406a8834a61e64e7c4d282aaa147e49ad8fa1cddb771bf24214c622619fe03117a468339713e9692d365f4b70dbcca86fb726f8f9
|
data/README.md
CHANGED
@@ -74,7 +74,7 @@ Specify multiple methods at once:
|
|
74
74
|
class MultiMonkey < Animal
|
75
75
|
include ProxyMethod
|
76
76
|
|
77
|
-
proxy_method
|
77
|
+
proxy_method :save, :update, raise: "Use an interactor!"
|
78
78
|
end
|
79
79
|
|
80
80
|
MultiMonkey.new.save
|
@@ -150,7 +150,7 @@ From there, you can allow your proxied block it to be used for multiple methods:
|
|
150
150
|
class MethodicalMeerkat < Animal
|
151
151
|
include ProxyMethod
|
152
152
|
|
153
|
-
proxy_method(
|
153
|
+
proxy_method(:save, :update) do |object, method_name|
|
154
154
|
"indirectly #{object.send(method_name)}!"
|
155
155
|
end
|
156
156
|
end
|
data/lib/proxy_method/version.rb
CHANGED
data/lib/proxy_method.rb
CHANGED
@@ -16,8 +16,14 @@ module ProxyMethod
|
|
16
16
|
@_proxy_class_methods_enabled = true
|
17
17
|
end
|
18
18
|
|
19
|
-
def proxy_class_method(original_method_names,
|
20
|
-
|
19
|
+
def proxy_class_method(*original_method_names, &proxy_block)
|
20
|
+
options = if original_method_names.last.is_a?(Hash)
|
21
|
+
original_method_names.pop
|
22
|
+
else
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
|
26
|
+
original_method_names = Array(original_method_names).flatten
|
21
27
|
|
22
28
|
error_message = options[:raise] || DEFAULT_PROXY_MESSAGE
|
23
29
|
prefix = options[:prefix] || DEFAULT_PREFIX
|
@@ -41,8 +47,14 @@ module ProxyMethod
|
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
44
|
-
def proxy_instance_method(original_method_names,
|
45
|
-
|
50
|
+
def proxy_instance_method(*original_method_names, &proxy_block)
|
51
|
+
options = if original_method_names.last.is_a?(Hash)
|
52
|
+
original_method_names.pop
|
53
|
+
else
|
54
|
+
{}
|
55
|
+
end
|
56
|
+
|
57
|
+
original_method_names = Array(original_method_names).flatten
|
46
58
|
|
47
59
|
error_message = options[:raise] || DEFAULT_PROXY_MESSAGE
|
48
60
|
prefix = options[:prefix] || DEFAULT_PREFIX
|
data/test/test_proxy_method.rb
CHANGED
@@ -52,6 +52,20 @@ class ProxyMethodTest < MiniTest::Test
|
|
52
52
|
assert_equal "Disabled by proxy_method", exception.message
|
53
53
|
end
|
54
54
|
|
55
|
+
it "allows multiple methods to be specified as a list of arguments" do
|
56
|
+
exception = assert_raises StandardError do
|
57
|
+
ListyLeopard.create
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_equal "Disabled by proxy_method", exception.message
|
61
|
+
|
62
|
+
exception = assert_raises StandardError do
|
63
|
+
ListyLeopard.destroy_all
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_equal "Disabled by proxy_method", exception.message
|
67
|
+
end
|
68
|
+
|
55
69
|
it "allows for a custom prefix" do
|
56
70
|
exception = assert_raises StandardError do
|
57
71
|
PrefixPelican.create
|
@@ -138,7 +152,7 @@ class ProxyMethodTest < MiniTest::Test
|
|
138
152
|
assert_equal 'indirectly saved!', MethodicalMeerkat.new.save
|
139
153
|
end
|
140
154
|
|
141
|
-
it "allows
|
155
|
+
it "allows multiple methods to be proxied in one call" do
|
142
156
|
exception = assert_raises StandardError do
|
143
157
|
MultiMonkey.new.save
|
144
158
|
end
|
@@ -152,6 +166,20 @@ class ProxyMethodTest < MiniTest::Test
|
|
152
166
|
assert_equal "Disabled by proxy_method", exception.message
|
153
167
|
end
|
154
168
|
|
169
|
+
it "allows multiple methods to be specified as a list of arguments" do
|
170
|
+
exception = assert_raises StandardError do
|
171
|
+
ListyLeopard.new.save
|
172
|
+
end
|
173
|
+
|
174
|
+
assert_equal "Disabled by proxy_method", exception.message
|
175
|
+
|
176
|
+
exception = assert_raises StandardError do
|
177
|
+
ListyLeopard.new.update
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_equal "Disabled by proxy_method", exception.message
|
181
|
+
end
|
182
|
+
|
155
183
|
it "allows for a custom prefix" do
|
156
184
|
exception = assert_raises StandardError do
|
157
185
|
PrefixPelican.new.save
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime Bellmyer
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- test/samples/animal.rb
|
39
39
|
- test/samples/animal/argumentative_aardvark.rb
|
40
40
|
- test/samples/animal/default_duck.rb
|
41
|
+
- test/samples/animal/listy_leopard.rb
|
41
42
|
- test/samples/animal/methodical_meerkat.rb
|
42
43
|
- test/samples/animal/multi_monkey.rb
|
43
44
|
- test/samples/animal/prefix_pelican.rb
|