123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Encryption::AutoFilteredParameters

Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/encryption/auto_filtered_parameters.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(app) ⇒ AutoFilteredParameters

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 6

def initialize(app)
  @app = app
  @attributes_by_class = Concurrent::Map.new
  @collecting = true

  install_collecting_hook
end

Instance Attribute Details

#app (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 20

attr_reader :app

#collecting?Boolean (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 44

def collecting?
  @collecting
end

Instance Method Details

#apply_collected_attributes (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 36

def apply_collected_attributes
  @attributes_by_class.each do |klass, attributes|
    attributes.each do |attribute|
      apply_filter(klass, attribute)
    end
  end
end

#apply_filter(klass, attribute) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 53

def apply_filter(klass, attribute)
  filter = [("#{klass.model_name.element}" if klass.name), attribute.to_s].compact.join(".")
  unless excluded_from_filter_parameters?(filter)
    app.config.filter_parameters << filter unless app.config.filter_parameters.include?(filter)
    klass.filter_attributes += [ attribute ]
  end
end

#attribute_was_declared(klass, attribute) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 28

def attribute_was_declared(klass, attribute)
  if collecting?
    collect_for_later(klass, attribute)
  else
    apply_filter(klass, attribute)
  end
end

#collect_for_later(klass, attribute) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 48

def collect_for_later(klass, attribute)
  @attributes_by_class[klass] ||= Concurrent::Array.new
  @attributes_by_class[klass] << attribute
end

#enable

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 14

def enable
  apply_collected_attributes
  @collecting = false
end

#excluded_from_filter_parameters?(filter_parameter) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 61

def excluded_from_filter_parameters?(filter_parameter)
  ActiveRecord::Encryption.config.excluded_from_filter_parameters.find { |excluded_filter| excluded_filter.to_s == filter_parameter }
end

#install_collecting_hook (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/encryption/auto_filtered_parameters.rb', line 22

def install_collecting_hook
  ActiveRecord::Encryption.on_encrypted_attribute_declared do |klass, attribute|
    attribute_was_declared(klass, attribute)
  end
end