Module: CzAuth::Concerns::Authentication::ClassMethods

Defined in:
app/controllers/cz_auth/concerns/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authentication_modelsObject

Determine which models are used for authentication



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/cz_auth/concerns/authentication.rb', line 16

def authentication_models
  @authentication_models ||= begin
    Dir.glob("app/models/*.rb").map do |file|
      model = File.basename(file, File.extname(file))
      resource = model.classify.constantize
      if resource.instance_methods.include?(:password)
        model
      end
    end
  end
end

#create_helper_methods_for(model) ⇒ Object

Defines helper methods, such as current_user



29
30
31
32
33
34
# File 'app/controllers/cz_auth/concerns/authentication.rb', line 29

def create_helper_methods_for(model)
  define_method(:"current_#{model}")       { current_resource(model)       }
  define_method(:"#{model}_signed_in?")    { resource_signed_in?(model)    }
  define_method(:"authenticate_#{model}!") { authenticate_resource!(model) }
  helper_method :"current_#{model}", :"#{model}_signed_in?"
end