class Voynich::Storage

Public Class Methods

new() click to toggle source
# File lib/voynich/storage.rb, line 5
def initialize
end

Public Instance Methods

create(plain_value, key_name: nil, context: {}) click to toggle source
# File lib/voynich/storage.rb, line 8
def create(plain_value, key_name: nil, context: {})
  data_key = fetch_data_key(key_name) unless key_name.nil?
  value = ActiveRecord::Value.create!(plain_value: plain_value, data_key: data_key, context: context)
  value.uuid
end
decrypt(uuid, context: {}) click to toggle source
# File lib/voynich/storage.rb, line 22
def decrypt(uuid, context: {})
  value = ActiveRecord::Value.find_by!(uuid: uuid)
  value.context = context
  value.decrypt
end
update(uuid, plain_value, context: {}) click to toggle source
# File lib/voynich/storage.rb, line 14
def update(uuid, plain_value, context: {})
  value = ActiveRecord::Value.find_by!(uuid: uuid)
  value.plain_value = plain_value
  value.context = context
  value.save!
  uuid
end

Private Instance Methods

fetch_data_key(key_name) click to toggle source
# File lib/voynich/storage.rb, line 30
def fetch_data_key(key_name)
  ActiveRecord::DataKey.find_or_create_by!(name: key_name, cmk_id: Voynich.kms_cmk_id)
end