Module: Skylight::Helpers::ClassMethods

Defined in:
lib/skylight/helpers.rb

Overview

See Also:

Instance Method Summary collapse

Instance Method Details

#instrument_methodObject #instrument_method([name], opts = {}) ⇒ Object

Overloads:

  • #instrument_methodObject

    Instruments the following method

    Examples:

    class MyClass
      include Skylight::Helpers
    
      instrument_method
      def my_method
        do_expensive_stuff
      end
    
    end
  • #instrument_method([name], opts = {}) ⇒ Object

    You may also declare the methods to instrument at any time by passing the name of the method as the first argument to ‘instrument_method`.

    By default, the event will be titled using the name of the class and the method. For example, in our previous example, the event name will be: MyClass#my_method. You can customize this by passing using the :title option.

    Examples:

    With name

    class MyClass
      include Skylight::Helpers
    
      def my_method
        do_expensive_stuff
      end
    
      instrument_method :my_method
    
    end

    Without name

    class MyClass
      include Skylight::Helpers
    
      instrument_method title: 'Expensive work'
      def my_method
        do_expensive_stuff
      end
    end

    Parameters:

    • [name] (Symbol|String)
    • opts (Hash) (defaults to: {})

    Options Hash (opts):

    • :category (String) — default: 'app.method'
    • :title (String) — default: ClassName#method_name
    • :description (String)


83
84
85
86
87
88
89
90
91
92
# File 'lib/skylight/helpers.rb', line 83

def instrument_method(*args)
  opts = args.pop if Hash === args.last

  if name = args.pop
    title = "#{to_s}##{name}"
    __sk_instrument_method_on(self, name, title, opts || {})
  else
    @__sk_instrument_next_method = opts || {}
  end
end

#method_added(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
# File 'lib/skylight/helpers.rb', line 13

def method_added(name)
  super

  if opts = @__sk_instrument_next_method
    @__sk_instrument_next_method = nil
    title = "#{to_s}##{name}"
    __sk_instrument_method_on(self, name, title, opts)
  end
end

#singleton_method_added(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
# File 'lib/skylight/helpers.rb', line 24

def singleton_method_added(name)
  super

  if opts = @__sk_instrument_next_method
    @__sk_instrument_next_method = nil
    title = "#{to_s}.#{name}"
    __sk_instrument_method_on(__sk_singleton_class, name, title, opts)
  end
end