Module: Cordon::MethodList

Included in:
Blacklist, Watchlist
Defined in:
lib/cordon/method_list.rb

Instance Method Summary collapse

Instance Method Details

#includes?(subject, method) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/cordon/method_list.rb', line 3

def includes?(subject, method)
  method_list.has_key?([subject, method])
end

#invoke_method(instance, subject, method, *args, &b) ⇒ Object



22
23
24
25
# File 'lib/cordon/method_list.rb', line 22

def invoke_method(instance, subject, method, *args, &b)
  unbound_method = method_list[[subject, method]]
  unbound_method.bind(instance).call(*args, &b)
end

#wrap_method(subject, method) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cordon/method_list.rb', line 13

def wrap_method(subject, method)
  return if includes?(subject, method)  # be idempotent

  # Unbind the original method, and replace it with a wrapper that
  # decides whether to bind and call the original
  unbind_method(subject, method)
  subject.__cordon__wrap_method__(method)
end

#wrap_methods(subject, methods) ⇒ Object



7
8
9
10
11
# File 'lib/cordon/method_list.rb', line 7

def wrap_methods(subject, methods)
  methods.each do |method|
    wrap_method(subject, method.to_sym)
  end
end