Class: Sentry::SymmetricSentryCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/symmetric_sentry_callback.rb

Instance Method Summary collapse

Constructor Details

#initialize(attr_name) ⇒ SymmetricSentryCallback

Returns a new instance of SymmetricSentryCallback.



3
4
5
# File 'lib/sentry/symmetric_sentry_callback.rb', line 3

def initialize(attr_name)
  @attr_name = attr_name
end

Instance Method Details

#after_save(model) ⇒ Object



13
14
15
# File 'lib/sentry/symmetric_sentry_callback.rb', line 13

def after_save(model)
  model.send("#{@attr_name}=", nil)
end

#before_validation(model) ⇒ Object

Performs encryption on before_validation Active Record callback



8
9
10
11
# File 'lib/sentry/symmetric_sentry_callback.rb', line 8

def before_validation(model)
  return if model.send(@attr_name).blank?
  model.send("crypted_#{@attr_name}=", SymmetricSentry.encrypt_to_base64(model.send(@attr_name)))
end