Module: Sequel::Plugins::Vault::ClassMethods

Defined in:
lib/sequel_vault.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#vault_attributes_moduleObject

Returns the value of attribute vault_attributes_module.



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

def vault_attributes_module
  @vault_attributes_module
end

Instance Method Details

#vault_attributes(keys, *attrs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sequel_vault.rb', line 15

def vault_attributes(keys, *attrs)
  include(self.vault_attributes_module ||= Module.new) unless vault_attributes_module
  vault_attributes_module.class_eval do
    attrs.each do |attr|
      define_method(attr) do
        cypher = super()
        decrypt(keys, cypher) unless cypher.nil?
      end

      define_method("#{attr}=") do |plain|
        cypher = encrypt(keys, plain) unless plain.nil?
        super(cypher)
      end
    end
  end
end