Module: Gardefou::GuardedClient::ClassMethods
- Defined in:
- lib/gardefou/wrapper.rb
Instance Method Summary collapse
-
#guard_method(method_name, **options) ⇒ Object
Class-level method to set up protection for specific methods.
-
#guard_methods(pattern, **options) ⇒ Object
Protect all methods matching a pattern.
Instance Method Details
#guard_method(method_name, **options) ⇒ Object
Class-level method to set up protection for specific methods
12 13 14 15 16 17 18 19 |
# File 'lib/gardefou/wrapper.rb', line 12 def guard_method(method_name, **) original_method = instance_method(method_name) guard = GardeFou.new(**) define_method(method_name) do |*args, **kwargs, &block| guard.call(original_method.bind(self), *args, **kwargs, &block) end end |
#guard_methods(pattern, **options) ⇒ Object
Protect all methods matching a pattern
22 23 24 25 26 |
# File 'lib/gardefou/wrapper.rb', line 22 def guard_methods(pattern, **) instance_methods.grep(pattern).each do |method_name| guard_method(method_name, **) end end |