ubiquitous_user 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +11 -0
- data/VERSION +1 -1
- data/lib/ubiquitous_user.rb +9 -10
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -119,6 +119,17 @@ You can use user= and authorize in the controllers, for example:
|
|
119
119
|
# ...
|
120
120
|
end
|
121
121
|
|
122
|
+
== The model
|
123
|
+
|
124
|
+
Ubiquitous User expects you to have a model for your users called User
|
125
|
+
(configurable) with a name field (also configurable). You could create such a
|
126
|
+
model with the following command:
|
127
|
+
|
128
|
+
./script/generate model User name:string
|
129
|
+
|
130
|
+
The name can be the real name, the username or anything. Ubiquitous user doesn't
|
131
|
+
make any assumptions about how you authenticate users.
|
132
|
+
|
122
133
|
== Customize
|
123
134
|
|
124
135
|
ubiquitous_user expects your user model to be named User. That's not
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/ubiquitous_user.rb
CHANGED
@@ -27,27 +27,26 @@ module UsableHelpers
|
|
27
27
|
# Helper method to get the current user. It will always return a user but the
|
28
28
|
# user may not be in the database. If options[:create] is true, then the user
|
29
29
|
# will be in the database (although it may be a ghost user).
|
30
|
-
def user(options = {:
|
31
|
-
#
|
32
|
-
|
30
|
+
def user(options = {:save => false})
|
31
|
+
# Find the user in the database if session[:user_id] is defined and @ubiquitous_user is not.
|
32
|
+
@ubiquitous_user = UsableConfig::user_model_class.find(session[:user_id]) if session[:user_id] != nil and @ubiquitous_user == nil
|
33
33
|
|
34
|
-
#
|
35
|
-
@ubiquitous_user = UsableConfig::user_model_class.
|
36
|
-
return @ubiquitous_user if @ubiquitous_user != nil
|
34
|
+
# Create a new user object if @ubiquitous_user is not defined.
|
35
|
+
@ubiquitous_user = UsableConfig::user_model_class.send(UsableConfig::user_model_new) if @ubiquitous_user == nil
|
37
36
|
|
38
|
-
#
|
39
|
-
@ubiquitous_user
|
40
|
-
if options[:create]
|
37
|
+
# If the object is new and we are asked to save, do it.
|
38
|
+
if @ubiquitous_user.new_record? and options[:save]
|
41
39
|
# Save the user in the database and set the session user_id for latter.
|
42
40
|
@ubiquitous_user.send(UsableConfig::user_model_save)
|
43
41
|
session[:user_id] = @ubiquitous_user.id
|
44
42
|
end
|
43
|
+
|
45
44
|
return @ubiquitous_user
|
46
45
|
end
|
47
46
|
|
48
47
|
# Helper method to get a user that for sure exists on the database.
|
49
48
|
def user!
|
50
|
-
return user(:
|
49
|
+
return user(:save => true)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubiquitous_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "J. Pablo Fern\xC3\xA1ndez"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11
|
12
|
+
date: 2009-12-11 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|