ubiquitous_user 0.1.1 → 0.2.0
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 +2 -0
- data/VERSION +1 -1
- data/generators/ubiquitous_user/templates/INSTALL +9 -0
- data/generators/ubiquitous_user/templates/initializer.rb +6 -0
- data/generators/ubiquitous_user/ubiquitous_user_generator.rb +9 -0
- data/lib/ubiquitous_user.rb +18 -5
- metadata +4 -3
- data/generators/ubiquitous_user/USAGE +0 -1
- data/generators/ubiquitous_user/ubiquitous_user.rb +0 -7
data/README.rdoc
CHANGED
@@ -126,6 +126,8 @@ configurable yet. What is configurable is the two methods it calls on user. You
|
|
126
126
|
can do this kind of configuration in config/initializers/ubiquitous_user.rb for
|
127
127
|
example:
|
128
128
|
|
129
|
+
UsableConfig::user_model = :Account
|
130
|
+
UsableConfig::user_model_new = :new_account
|
129
131
|
UsableConfig::user_model_save = :save_bypassing_non_essential_validation
|
130
132
|
UsableConfig::user_model_name = :name_or_else
|
131
133
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Thank you for trying ubiquitous_user. To get all the magic going you need to
|
2
|
+
add usable to your application_controller.rb, something like:
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
include Usable
|
6
|
+
#...
|
7
|
+
end
|
8
|
+
|
9
|
+
For more information see: http://github.com/pupeno/ubiquitous_user
|
data/lib/ubiquitous_user.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
module UsableConfig
|
2
|
+
@user_model = :User
|
3
|
+
@user_model_new = :new
|
2
4
|
@user_model_save = :save
|
3
5
|
@user_model_name = :name
|
4
6
|
|
7
|
+
# Class that defines the user model.
|
8
|
+
attr_accessor :user_model
|
9
|
+
module_function :user_model, :user_model=
|
10
|
+
# Method used to create a new user, of class user_model
|
11
|
+
attr_accessor :user_model_new
|
12
|
+
module_function :user_model_new, :user_model_new=
|
5
13
|
# Method used to save the user.
|
6
14
|
attr_accessor :user_model_save
|
15
|
+
module_function :user_model_save, :user_model_save=
|
7
16
|
# Method used to get the name of the user.
|
8
17
|
attr_accessor :user_model_name
|
9
|
-
|
10
|
-
|
18
|
+
module_function :user_model_name, :user_model_name=
|
19
|
+
|
20
|
+
def user_model_class # :nodoc:
|
21
|
+
Object.const_get(user_model)
|
22
|
+
end
|
23
|
+
module_function :user_model_class
|
11
24
|
end
|
12
25
|
|
13
26
|
module UsableHelpers
|
@@ -19,11 +32,11 @@ module UsableHelpers
|
|
19
32
|
return @ubiquitous_user if @ubiquitous_user != nil
|
20
33
|
|
21
34
|
# Try to find the user in the database if session[:user_id] is defined.
|
22
|
-
@ubiquitous_user =
|
35
|
+
@ubiquitous_user = UsableConfig::user_model_class.find(session[:user_id]) if session[:user_id] != nil
|
23
36
|
return @ubiquitous_user if @ubiquitous_user != nil
|
24
37
|
|
25
38
|
# Create a new user object.
|
26
|
-
@ubiquitous_user =
|
39
|
+
@ubiquitous_user = UsableConfig::user_model_class.send(UsableConfig::user_model_new)
|
27
40
|
if options[:create]
|
28
41
|
# Save the user in the database and set the session user_id for latter.
|
29
42
|
@ubiquitous_user.send(UsableConfig::user_model_save)
|
@@ -52,7 +65,7 @@ module Usable
|
|
52
65
|
end
|
53
66
|
|
54
67
|
def authorize
|
55
|
-
unless
|
68
|
+
unless UsableConfig::user_model_class.find_by_id(session[:user_id]) and session[:user_name] != nil
|
56
69
|
flash[:notice] = "Please log in."
|
57
70
|
redirect_to new_session_url
|
58
71
|
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "J. Pablo Fern\xC3\xA1ndez"
|
@@ -36,8 +36,9 @@ files:
|
|
36
36
|
- README.rdoc
|
37
37
|
- Rakefile
|
38
38
|
- VERSION
|
39
|
-
- generators/ubiquitous_user/
|
40
|
-
- generators/ubiquitous_user/
|
39
|
+
- generators/ubiquitous_user/templates/INSTALL
|
40
|
+
- generators/ubiquitous_user/templates/initializer.rb
|
41
|
+
- generators/ubiquitous_user/ubiquitous_user_generator.rb
|
41
42
|
- lib/ubiquitous_user.rb
|
42
43
|
has_rdoc: true
|
43
44
|
homepage: http://github.com/pupeno/ubiquitous_user
|
@@ -1 +0,0 @@
|
|
1
|
-
blah blah
|