lam_auth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,30 @@
1
1
  module LamAuth
2
2
  module ControllerExtensions
3
3
  def lam_auth_for(klass)
4
- class_inheritable_accessor :model_class
5
- self.model_class = klass.to_s.classify.constantize
4
+ class_inheritable_writer :user_model_class
5
+ self.user_model_class = klass
6
+
6
7
  helper_method(:current_user, :logged_in?)
7
8
  before_filter :login_from_cookie
8
9
 
10
+ extend ClassMethods
9
11
  include InstanceMethods
10
12
  protected :logged_in?, :current_user, :current_user=, :auth_token, :login_from_cookie, :login_required
11
13
  end
12
14
 
15
+ module ClassMethods
16
+ def user_model_class
17
+ read_inheritable_attribute(:user_model_class).to_s.classify.constantize
18
+ end
19
+ end
20
+
13
21
  module InstanceMethods
14
22
  def logged_in?
15
23
  !!current_user
16
24
  end
17
25
 
18
26
  def current_user
19
- @current_user ||= session[:user] && model_class.find_by_id(session[:user])
27
+ @current_user ||= session[:user] && self.class.user_model_class.find_by_id(session[:user])
20
28
  end
21
29
 
22
30
  def current_user=(new_user)
@@ -33,7 +41,7 @@ module LamAuth
33
41
  if logged_in?
34
42
  !auth_token && self.current_user = nil
35
43
  else
36
- auth_token && self.current_user = model_class.find_by_auth_token(auth_token)
44
+ auth_token && self.current_user = self.class.user_model_class.find_by_auth_token(auth_token)
37
45
  end
38
46
  end
39
47
 
@@ -1,3 +1,3 @@
1
1
  module LamAuth
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lam_auth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Max Macovsky
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-21 00:00:00 +04:00
19
+ date: 2011-04-23 00:00:00 +04:00
20
20
  default_executable:
21
21
  dependencies: []
22
22