Module: ProxyMethod::ClassMethods

Defined in:
lib/proxy_method.rb

Constant Summary collapse

DEFAULT_PROXY_MESSAGE =
'Disabled by proxy_method'
DEFAULT_PREFIX =
'unproxied_'

Instance Method Summary collapse

Instance Method Details

#proxy_class_method(original_method_names, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/proxy_method.rb', line 6

def proxy_class_method(original_method_names, options = {})
  error_message = options[:message] || DEFAULT_PROXY_MESSAGE
  prefix = options[:prefix] || DEFAULT_PREFIX

  Array(original_method_names).each do |original_method_name|
    self.singleton_class.send(:alias_method, :"#{prefix}#{original_method_name}", original_method_name)
    define_singleton_method(original_method_name){ raise error_message }
  end
end

#proxy_instance_method(original_method_names, options = {}) ⇒ Object Also known as: proxy_method



16
17
18
19
20
21
22
23
24
# File 'lib/proxy_method.rb', line 16

def proxy_instance_method(original_method_names, options = {})
  error_message = options[:message] || DEFAULT_PROXY_MESSAGE
  prefix = options[:prefix] || DEFAULT_PREFIX

  Array(original_method_names).each do |original_method_name|
    alias_method :"#{prefix}#{original_method_name}", original_method_name
    define_method(original_method_name){ raise error_message }
  end
end