module Informed::DSL

When extended, this adds the `inform_on` class method to the class it's mixed in to.

Public Instance Methods

inform_on(method, level:, also_log: {}) click to toggle source

Logs method calls to the named method @param method [Symbol] Name of method to inform upon @param level [:debug, :info, :warn, :error, :fatal, :unknown] which level

calls to this method at.

@param also_log [Hash] See {Informant#also_log}

# File lib/informed.rb, line 91
def inform_on(method, level:, also_log: {})
  alias_method :"unwatched_#{method}", method
  informant = Informant.new(method: method, also_log: also_log, level: level)
  define_method method do |*arguments, **keyword_arguments, &block|
    informant.inform_on(informee: self,
                        logger: logger,
                        arguments: arguments,
                        keyword_arguments: keyword_arguments,
                        block: block)
  end
end