Module: Saml::Notification::ClassMethods

Defined in:
lib/saml/notification.rb

Instance Method Summary collapse

Instance Method Details

#method_added(name) ⇒ Object



52
53
54
# File 'lib/saml/notification.rb', line 52

def method_added(name)
  wrap_with_notification(name, true) if should_wrap?(name)
end

#notify(method, result) ⇒ Object



27
28
29
30
31
# File 'lib/saml/notification.rb', line 27

def notify(method, result)
  class_name = self.name.demodulize.underscore
  ActiveSupport::Notifications.instrument "#{method}.#{class_name}.saml", result
  result
end

#notify_on(*options) ⇒ Object



33
34
35
# File 'lib/saml/notification.rb', line 33

def notify_on(*options)
  options.present? ? @notify_on = options : @notify_on
end

#should_wrap?(name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
# File 'lib/saml/notification.rb', line 37

def should_wrap?(name)
  @notify_on ||= []
  @exclude   ||= []

  return false if @notify_on.exclude?(name) || @exclude.include?(name.to_s)
  @exclude << "#{name}_with_notification"
  @exclude << "#{name}_without_notification"
  @exclude << "#{name}"
  true
end

#singleton_method_added(name) ⇒ Object



48
49
50
# File 'lib/saml/notification.rb', line 48

def singleton_method_added(name)
  wrap_with_notification(name, false) if should_wrap?(name)
end

#wrap_with_notification(method, instance_method) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/saml/notification.rb', line 10

def wrap_with_notification(method, instance_method)
  wrapper = "    define_method \"\#{method}_with_notification\" do |*args|\n      notify \"\#{method}\", send(\"\#{method}_without_notification\", *args)\n    end\n\n    alias_method \"\#{method}_without_notification\", :\#{method}\n    alias_method :\#{method}, \"\#{method}_with_notification\"\n  RUBY\n\n  if instance_method\n    class_eval wrapper\n  else\n    class_eval \"class << self; \#{wrapper}; end\"\n  end\nend\n"