Class: ActiveModel::MassAssignmentSecurity::LoggerSanitizer

Inherits:
Sanitizer
  • Object
show all
Defined in:
lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Sanitizer

#sanitize

Constructor Details

#initialize(target) ⇒ LoggerSanitizer

Returns a new instance of LoggerSanitizer


22
23
24
25
# File 'lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb', line 22

def initialize(target)
  @target = target
  super()
end

Instance Method Details

#backtraceObject


35
36
37
38
39
40
41
# File 'lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb', line 35

def backtrace
  if defined? Rails
    Rails.backtrace_cleaner.clean(caller)
  else
    caller
  end
end

#loggerObject


27
28
29
# File 'lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb', line 27

def logger
  @target.logger
end

#logger?Boolean

Returns:


31
32
33
# File 'lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb', line 31

def logger?
  @target.respond_to?(:logger) && @target.logger
end

#process_removed_attributes(klass, attrs) ⇒ Object


43
44
45
46
47
48
49
50
# File 'lib/mongomodel/vendor/active_model/mass_assignment_security/sanitizer.rb', line 43

def process_removed_attributes(klass, attrs)
  if logger?
    logger.warn do
      "WARNING: Can't mass-assign protected attributes for #{klass.name}: #{attrs.join(', ')}\n" +
          backtrace.map { |trace| "\t#{trace}" }.join("\n")
    end
  end
end