Module: SimplestAuth::Model::ClassMethods

Defined in:
lib/simplest_auth/model.rb

Instance Method Summary collapse

Instance Method Details

#active_record?Boolean

Returns:



23
24
25
# File 'lib/simplest_auth/model.rb', line 23

def active_record?
  defined?(ActiveRecord)
end

#authenticate(email, password) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/simplest_auth/model.rb', line 31

def authenticate(email, password)
  if active_record?
    klass = find_by_email(email)
  elsif data_mapper?
    klass = first(:email => email)
  end

  (klass && klass.authentic?(password)) ? klass : nil
end

#authenticate_by(ident) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/simplest_auth/model.rb', line 41

def authenticate_by(ident)
  if active_record?
    instance_eval "      def authenticate(\#{ident}, password)\n        klass = find_by_\#{ident}(\#{ident})\n        (klass && klass.authentic?(password)) ? klass : nil\n      end\n    EOM\n  elsif data_mapper?\n    instance_eval <<-EOM\n      def authenticate(\#{ident}, password)\n        klass = first(:\#{ident} => \#{ident})\n        (klass && klass.authentic?(password)) ? klass : nil\n      end\n    EOM\n  end\nend\n"

#data_mapper?Boolean

Returns:



27
28
29
# File 'lib/simplest_auth/model.rb', line 27

def data_mapper?
  defined?(DataMapper)
end