module Authenticate::Modules::ClassMethods

Class methods injected into User model.

Public Instance Methods

load_modules() click to toggle source

Load all modules declared in Authenticate.configuration.modules. Requires them, then loads as a constant, then checks fields, and finally includes.

@raise MissingAttribute if attributes required by Authenticate are missing.

# File lib/authenticate/modules.rb, line 35
def load_modules
  modules_to_include = []
  Authenticate.configuration.modules.each do |mod|
    # The built-in modules are referred to by symbol. Additional module classes (constants) can be added
    # via Authenticate.configuration.modules.
    require "authenticate/model/#{mod}" if mod.is_a?(Symbol)
    mod = load_constant(mod) if mod.is_a?(Symbol)
    modules_to_include << mod
  end
  check_fields modules_to_include
  modules_to_include.each { |mod| include mod }
end

Private Instance Methods

check_fields(modules) click to toggle source

For each module, look at the fields it requires. Ensure the User model including the module has the required fields. @raise MissingAttribute if required attributes are missing.

# File lib/authenticate/modules.rb, line 57
def check_fields(modules)
  failed_attributes = []
  instance = new
  modules.each do |mod|
    if mod.respond_to?(:required_fields)
      mod.required_fields(self).each { |field| failed_attributes << field unless instance.respond_to?(field) }
    end
  end

  if failed_attributes.any?
    raise MissingAttribute.new(failed_attributes),
          "Required attribute are missing on your user model: #{failed_attributes.join(', ')}"
  end
end
load_constant(module_symbol) click to toggle source
# File lib/authenticate/modules.rb, line 50
def load_constant(module_symbol)
  Authenticate::Model.const_get(module_symbol.to_s.classify)
end