module QuoVadis

Much of this comes from Rodauth.

Constants

Error
PasswordExistsError
VERSION

Public Class Methods

accessor(*names) click to toggle source
# File lib/quo_vadis.rb, line 8
def self.accessor(*names)
  names.each do |name|
    define_singleton_method name do |val = nil|
      if !val.nil?
        instance_variable_set :"@#{name}", val
      else
        instance_variable_get :"@#{name}"
      end
    end
  end
end
configure(&block) click to toggle source
# File lib/quo_vadis.rb, line 37
def configure(&block)
  module_eval &block
end
deliver(action, params) click to toggle source
# File lib/quo_vadis.rb, line 79
def deliver(action, params)
  mail = QuoVadis::Mailer.with(params).send(action)
  QuoVadis.enqueue_transactional_emails ?
    mail.deliver_later :
    mail.deliver_now
end
find_account_by_identifier_in_params(params) click to toggle source
# File lib/quo_vadis.rb, line 47
def find_account_by_identifier_in_params(params)
  Account.find_by identifier: identifier_value_in_params(params)
end
humanise_identifier(model) click to toggle source

model - string class name, e.g. 'User' returns string humanised name for the model's identifier, e.g. “Username”

# File lib/quo_vadis.rb, line 58
def humanise_identifier(model)
  klass = model.constantize
  klass.human_attribute_name identifier(model)
end
identifier(model) click to toggle source

model - string class name, e.g. 'User' returns attribute symbol, e.g. :username

# File lib/quo_vadis.rb, line 88
def identifier(model)
  models[model]
end
identifier_value_in_params(params) click to toggle source
# File lib/quo_vadis.rb, line 51
def identifier_value_in_params(params)
  identifier = detect_identifier params.keys
  params[identifier]
end
notify(action, params) click to toggle source
# File lib/quo_vadis.rb, line 75
def notify(action, params)
  QuoVadis::Mailer.with(params).send(action).deliver_later
end
register_model(name, identifier) click to toggle source

name - string class name, e.g. 'User' identifier - attribute symbol, e.g. :username

# File lib/quo_vadis.rb, line 43
def register_model(name, identifier)
  models[name] = identifier
end
table_name_prefix() click to toggle source
# File lib/quo_vadis/engine.rb, line 5
def self.table_name_prefix
  'qv_'
end
translate(key, **options) click to toggle source

Translates the key in the :quo_vadis scope, returning nil if it does not exist. This allows applications to suppress a QuoVadis translation. For example:

en:
  quo_vadis:
    require_authentication:
# File lib/quo_vadis.rb, line 71
def translate(key, **options)
  I18n.t key, **options.merge(scope: :quo_vadis, raise: true) rescue nil
end

Private Class Methods

detect_identifier(candidates) click to toggle source
# File lib/quo_vadis.rb, line 98
def detect_identifier(candidates)
  (identifiers.map(&:to_s) & candidates.map(&:to_s)).first
end
identifiers() click to toggle source
# File lib/quo_vadis.rb, line 102
def identifiers
  models.values.uniq
end
models() click to toggle source
# File lib/quo_vadis.rb, line 94
def models
  @models ||= {}
end