Sha256: 02376debb61e0b4638d35b2582711a6acf0e3e7aedd66174dd92b6b605c4c139

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

require 'active_record'
require 'logger'

ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.logger.level = ENV['LOG_LEVEL'] || Logger::WARN
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])

ActiveRecord::Schema.define do
  enable_extension 'pgcrypto'

  create_table :users, force: true do |t|
    t.binary :email
  end
end

# Enable PGCrypto Symmetric encryption support.
ENV['PGCRYPTO_SYM_KEY'] = SecureRandom.hex(10)
require 'active_record/pgcrypto'

class User < ActiveRecord::Base
  serialize(:email, ActiveRecord::PGCrypto::SymmetricCoder)

  def self.decrypted_email
    ActiveRecord::PGCrypto::SymmetricCoder
      .decrypted_arel_text(arel_table[:email])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record-pgcrypto-0.2.6 spec/dummy.rb
active_record-pgcrypto-0.2.5 spec/dummy.rb