Module: Informed::DSL

Defined in:
lib/informed.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#inform_on(method, level:, also_log: {}) ⇒ Object

Logs method calls to the named method



91
92
93
94
95
96
97
98
99
100
101
# 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