Module: SimpleAuth::ActiveRecord::Macro

Defined in:
lib/simple_auth/active_record.rb

Instance Method Summary collapse

Instance Method Details

#authentication(&block) ⇒ Object

Set virtual attributes, callbacks and validations. Is called automatically after setting up configuration with SimpleAuth.setup {|config| config.model = :user}.

class User < ActiveRecord::Base
authentication
end

Can set configuration when a block is provided.

class User < ActiveRecord::Base
authentication do |config|
  config.credentials = ["email"]
end
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/simple_auth/active_record.rb', line 24

def authentication(&block)
  SimpleAuth.setup(&block) if block_given?
  SimpleAuth::Config.model ||= name.underscore.to_sym

  # Possibly multiple calls in a given model.
  # So, just return.
  return if respond_to?(:authenticate)

  has_secure_password

  extend  ClassMethods
  include InstanceMethods

  validates_length_of :password, minimum: 4
end