Sha256: 6380801dcad2e0cc3f8ab4e96d0be6f11551d619d7412298c3808765ced23a57

Contents?: true

Size: 977 Bytes

Versions: 5

Compression:

Stored size: 977 Bytes

Contents

require "binary_serializer"

class LazyPerson < ActiveRecord::Base
  include Vault::EncryptedModel

  self.table_name = "people"

  vault_lazy_decrypt!

  vault_attribute :ssn

  vault_attribute :credit_card,
    encrypted_column: :cc_encrypted,
    path: "credit-secrets",
    key: "people_credit_cards"

  vault_attribute :details,
    serialize: :json

  vault_attribute :business_card,
    serialize: BinarySerializer

  vault_attribute :favorite_color,
    encode: ->(raw) { "xxx#{raw}xxx" },
    decode: ->(raw) { raw && raw[3...-3] }

  vault_attribute :non_ascii

  vault_attribute :default,
    default: "abc123"

  vault_attribute :default_with_serializer,
    serialize: :json,
    default: {}

  vault_attribute :context_string,
    context: "production"

  vault_attribute :context_symbol,
    context: :encryption_context

  vault_attribute :context_proc,
    context: ->(record) { record.encryption_context }

  def encryption_context
    "user_#{id}"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vault-rails-0.8.0 spec/dummy/app/models/lazy_person.rb
vault-rails-0.7.1 spec/dummy/app/models/lazy_person.rb
vault-rails-0.7.0 spec/dummy/app/models/lazy_person.rb
vault-rails-0.6.0 spec/dummy/app/models/lazy_person.rb
vault-rails-0.5.0 spec/dummy/app/models/lazy_person.rb