Module: AttrRedactor::InstanceMethods
- Defined in:
- lib/attr_redactor.rb
Instance Method Summary collapse
-
#redact(attribute, value) ⇒ Object
Redacts a value for the attribute specified using options evaluated in the current object’s scope.
-
#redacted_attributes ⇒ Object
Copies the class level hash of redacted attributes with virtual attribute names as keys and their corresponding options as values to the instance.
-
#unredact(attribute, redacted_value) ⇒ Object
Decrypts a value for the attribute specified using options evaluated in the current object’s scope.
Instance Method Details
#redact(attribute, value) ⇒ Object
Redacts a value for the attribute specified using options evaluated in the current object’s scope
Example
class User
attr_accessor :secret_key
attr_redactor :data, key: :secret_key
def initialize(secret_key)
self.secret_key = secret_key
end
end
@user = User.new('some-secret-key')
@user.redact(:data, '[email protected]')
268 269 270 271 |
# File 'lib/attr_redactor.rb', line 268 def redact(attribute, value) redacted_attributes[attribute.to_sym][:operation] = :redacting self.class.redact(attribute, value, (attribute)) end |
#redacted_attributes ⇒ Object
Copies the class level hash of redacted attributes with virtual attribute names as keys and their corresponding options as values to the instance
276 277 278 |
# File 'lib/attr_redactor.rb', line 276 def redacted_attributes @redacted_attributes ||= self.class.redacted_attributes.dup end |
#unredact(attribute, redacted_value) ⇒ Object
Decrypts a value for the attribute specified using options evaluated in the current object’s scope
Example
class User
attr_accessor :secret_key
attr_redactor :data, key: :secret_key
def initialize(secret_key)
self.secret_key = secret_key
end
end
@user = User.new('some-secret-key')
@user.unredact(:data, SOME_REDACTED_HASH)
248 249 250 251 |
# File 'lib/attr_redactor.rb', line 248 def unredact(attribute, redacted_value) redacted_attributes[attribute.to_sym][:operation] = :unredacting self.class.unredact(attribute, redacted_value, (attribute)) end |