Module: Saml::Notification::ClassMethods
- Defined in:
- lib/saml/notification.rb
Instance Method Summary collapse
- #method_added(name) ⇒ Object
- #notify(method, result) ⇒ Object
- #notify_on(*options) ⇒ Object
- #should_wrap?(name) ⇒ Boolean
- #singleton_method_added(name) ⇒ Object
- #wrap_with_notification(method, instance_method) ⇒ Object
Instance Method Details
#method_added(name) ⇒ Object
50 51 52 |
# File 'lib/saml/notification.rb', line 50 def method_added(name) wrap_with_notification(name, true) if should_wrap?(name) end |
#notify(method, result) ⇒ Object
25 26 27 28 29 |
# File 'lib/saml/notification.rb', line 25 def notify(method, result) class_name = self.name.demodulize.underscore ActiveSupport::Notifications.instrument "#{method}.#{class_name}.saml", result result end |
#notify_on(*options) ⇒ Object
31 32 33 |
# File 'lib/saml/notification.rb', line 31 def notify_on(*) .present? ? @notify_on = : @notify_on end |
#should_wrap?(name) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/saml/notification.rb', line 35 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
46 47 48 |
# File 'lib/saml/notification.rb', line 46 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 |
# File 'lib/saml/notification.rb', line 10 def wrap_with_notification(method, instance_method) wrapper = <<-RUBY define_method "#{method}_with_notification" do |*args| notify "#{method}", send("#{method}_without_notification", *args) end alias_method_chain :#{method}, :notification RUBY if instance_method class_eval wrapper else class_eval "class << self; #{wrapper}; end" end end |