Class: ValidationError

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/validation_error.rb

Class Method Summary collapse

Class Method Details

.filter_sensible_information(details) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/validation_error.rb', line 12

def self.filter_sensible_information(details)
  filter_parameters = if defined?(Rails) && Rails.respond_to?(:application)
    Rails.application.config.filter_parameters
  else
    []
  end
  filtered_details = details.dup
  filtered_details.each do |column_name, errors|
    filter_parameters.each do |filter|
      must_filter = case filter
                    when Regexp
                      filter.match?(column_name)
                    when String, Symbol
                      filter.to_s == column_name.to_s
      end
      if must_filter
        errors.each do |error|
          if error[:value].present?
            error[:value] = "***"
          end
        end
      end
    end
  end
  filtered_details
end

.track(invalid_model, action: invalid_model.persisted? ? "update" : "create") ⇒ Object



4
5
6
7
8
9
10
# File 'lib/validation_error.rb', line 4

def self.track(invalid_model, action: invalid_model.persisted? ? "update" : "create")
  details = filter_sensible_information(invalid_model.errors.details)
  create!(invalid_model_name: invalid_model.class.name,
          invalid_model_id: invalid_model.id,
          details: details,
          action: action)
end