Module: Loggun::Helpers::ClassMethods

Defined in:
lib/loggun/helpers.rb

Instance Method Summary collapse

Instance Method Details

#log_options(**options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/loggun/helpers.rb', line 36

def log_options(**options)
  @log_entity_name = options[:entity_name]
  @log_entity_action = options[:entity_action]
  @with_log_transaction_id = options[:as_transaction]
  @log_transaction_generator = options[:transaction_generator]
  @log_transaction_except = options[:log_transaction_except]&.map(&:to_sym)
  @log_skip_methods = options[:except]&.map(&:to_sym)
  @log_only_methods = options[:only]&.map(&:to_sym)
  @log_all_methods = options[:log_all_methods]
end

#method_added(method_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/loggun/helpers.rb', line 47

def method_added(method_name)
  super
  @log_modified_methods ||= []

  return if !log_all_methods && !log_only_methods&.include?(method_name)
  return if log_skip_methods&.include?(method_name)
  return if SKIPPED_METHODS.include?(method_name) || log_modified_methods.include?(method_name)

  log_modified_methods << method_name
  method = instance_method(method_name)
  undef_method(method_name)

  define_method(method_name) do |*args, &block|
    if self.class.log_transaction_except&.include?(method_name.to_sym)
      method.bind(self).call(*args, &block)
    else
      type = log_type(nil, method_name)
      in_log_transaction(type) do
        method.bind(self).call(*args, &block)
      end
    end
  end
end