Module: Vhost::SiteScopedModelExtensions::ClassMethods

Defined in:
lib/vhost/site_scoped_model_extensions.rb

Instance Method Summary collapse

Instance Method Details

#clear_callbacks_by_calling_method_name(kind, calling_method_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vhost/site_scoped_model_extensions.rb', line 24

def clear_callbacks_by_calling_method_name(kind, calling_method_name)
  calling_method_name = calling_method_name.to_s
  # Callbacks are stored by kind as instance variables named @<kind>_callbacks. 
  # Fetch them so we can kick out the matching items.
  callback_chain = eval("@#{kind.to_s}_callbacks")
  unless callback_chain.nil?
    callback_chain.reject! do |callback|
      method = callback.method
      if method.is_a?(Proc)
        # Returns the symbol for the method the proc was declared in
        current_calling_method_name = eval("caller[0] =~ /`([^']*)'/ and $1", method.binding).to_s rescue nil
        current_calling_method_name == calling_method_name
      else
        false
      end
    end
  end
end