module Voltron::Encryptable::ClassMethods

Public Instance Methods

delete(id) click to toggle source
Calls superclass method
# File lib/voltron/encryptable.rb, line 47
def delete(id)
  super(decoded_ids(id))
end
destroy(id) click to toggle source
Calls superclass method
# File lib/voltron/encryptable.rb, line 43
def destroy(id)
  super(decoded_ids(id))
end
exists?(conditions = :none) click to toggle source
Calls superclass method
# File lib/voltron/encryptable.rb, line 33
def exists?(conditions = :none)
  if conditions.is_a?(String)
    # If conditions is a string, assume it's an encoded id
    super(decoded_ids(conditions))
  else
    # Otherwise do what exists? normally does
    super
  end
end
find(*args) click to toggle source
Calls superclass method
# File lib/voltron/encryptable.rb, line 22
def find(*args)
  scope = args.slice!(0)
  options = args.slice!(0) || {}

  if !options[:bypass] && ![:first, :last, :all].include?(scope.try(:to_sym))
    scope = decoded_ids(scope)
  end

  super(scope)
end
has_encrypted_id?() click to toggle source
# File lib/voltron/encryptable.rb, line 18
def has_encrypted_id?
  true
end

Private Instance Methods

decoded_ids(*ids) click to toggle source
# File lib/voltron/encryptable.rb, line 53
def decoded_ids(*ids)
  crypt = Voltron::Encrypt.new

  ids.flatten!
  ids.map! { |id| crypt.decode(id).to_i }
  ids.reject! { |id| id > 9223372036854775807 } # Remove id if given decoded value is greater than max PostgreSQL value
  ids = Voltron::Id.where(id: ids).pluck(:resource_id)
  ids = ids.first if ids.length == 1
  ids
end