proxy_method 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30dca7d6e6868dad470c1c00056727bfc78c0c1ec457d95876c0fd42cd2b8bb5
4
- data.tar.gz: d805267647962b76433660771e691090fd94b0c23643ae704916b11aaaa5fa65
3
+ metadata.gz: 6f4af87ac13ed1ecd407497936bce7b5e57f16be2348460de75c65c490a756ec
4
+ data.tar.gz: 344cc71d86ce1c8af010fe28ef7e8c6040de4237e2673806fbd822595927f684
5
5
  SHA512:
6
- metadata.gz: 3a5f7ab8a5f2d0e03064d80635e2857588ba3f983a2de14f9acbf62d37736ec9dd835217304aa7c5414ab4be44a2408cc83771ccfd94a82dcdb2e697ed5a0e80
7
- data.tar.gz: 547f5b2e3886c9b9841339aec6751393807375c772e7d2175c9617422c65eb2811fe2c7f88768fa19339e586bad1ba578ff67646131d0880b3afc1779a8f9201
6
+ metadata.gz: 379a2267013b8b47ee6c901a87acac2794103f049651b0eb50743d2deb5477afc14acb0ce94d38b4940ca19dcbf15138745484138e903e1a3ace957beecf1409
7
+ data.tar.gz: d54ad49a095ec66ade4d46dfd299f835b651fa09554b79e3c59d98512643c8f1ac4827f9720b7e623e6bd09cb35603a2c6f3fd834a4cd9f63fa8fce6e86b0688
data/lib/proxy_method.rb CHANGED
@@ -50,7 +50,7 @@ module ProxyMethod
50
50
  # Dog.create
51
51
  # # => RuntimeError: Disabled!
52
52
  #
53
- # You can still access the unproxied version by prefixing 'unproxied'
53
+ # You can still access the unproxied version by prefixing 'unproxied_'
54
54
  # to the method name:
55
55
  #
56
56
  # Dog.unproxied_create
@@ -74,10 +74,9 @@ module ProxyMethod
74
74
  # end
75
75
  # end
76
76
  #
77
- # Dog.original_create
77
+ # Dog.create
78
78
  # # => 'indirectly created'
79
79
 
80
-
81
80
  def proxy_class_method(*original_method_names, &proxy_block)
82
81
  options = if original_method_names.last.is_a?(Hash)
83
82
  original_method_names.pop
@@ -109,6 +108,87 @@ module ProxyMethod
109
108
  end
110
109
  end
111
110
 
111
+ ##
112
+ # Proxy one or more inherited instance methods, so that they are not used
113
+ # directly. Given this base class:
114
+ #
115
+ # class Animal
116
+ # def save
117
+ # 'saved'
118
+ # end
119
+ #
120
+ # def update
121
+ # 'updated'
122
+ # end
123
+ # end
124
+ #
125
+ # The simplest implementation is to pass just a single method name:
126
+ #
127
+ # class Dog < Animal
128
+ # proxy_instance_method :save
129
+ # end
130
+ #
131
+ # Dog.new.save
132
+ # # => RuntimeError: Disabled by proxy_method
133
+ #
134
+ # Dog.new.upate
135
+ # # 'updated'
136
+ #
137
+ #
138
+ # Or use the shorthand form:
139
+ #
140
+ # class Dog < Animal
141
+ # proxy_method :save
142
+ # end
143
+ #
144
+ # Or multiple method names:
145
+ #
146
+ # class Dog < Animal
147
+ # proxy_method :save, :update
148
+ # end
149
+ #
150
+ # Dog.new.save
151
+ # # => RuntimeError: Disabled by proxy_method
152
+ #
153
+ # Dog.new.update
154
+ # # => RuntimeError: Disabled by proxy_method
155
+ #
156
+ # With a custom error message:
157
+ #
158
+ # class Dog < Animal
159
+ # proxy_method :save, raise: 'Disabled!'
160
+ # end
161
+ #
162
+ # Dog.new.save
163
+ # # => RuntimeError: Disabled!
164
+ #
165
+ # You can still access the unproxied version by prefixing 'unproxied_'
166
+ # to the method name:
167
+ #
168
+ # Dog.new.unproxied_save
169
+ # # => 'saved'
170
+ #
171
+ # And you can change the prefix for unproxied versions:
172
+ #
173
+ # class Dog < Animal
174
+ # proxy_method :save, prefix: 'original_'
175
+ # end
176
+ #
177
+ # Dog.new.original_save
178
+ # # => 'saved'
179
+ #
180
+ # Finally, you can actually *proxy* the method, by providing an
181
+ # alternative block of code to run:
182
+ #
183
+ # class Dog < Animal
184
+ # proxy_method(:save) do |object, method_name, *args, &block|
185
+ # "indirectly #{object.send(method_name)}"
186
+ # end
187
+ # end
188
+ #
189
+ # Dog.new.save
190
+ # # => 'indirectly saved'
191
+
112
192
  def proxy_instance_method(*original_method_names, &proxy_block)
113
193
  options = if original_method_names.last.is_a?(Hash)
114
194
  original_method_names.pop
@@ -1,3 +1,3 @@
1
1
  module ProxyMethod
2
- VERSION='1.2.5'
2
+ VERSION='1.2.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-06 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  The purpose of this gem is to prevent directly running the inherited