roles_mongoid 0.3.3 → 0.3.4
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -5,6 +5,8 @@ module Mongoid
|
|
5
5
|
module Generators
|
6
6
|
class RolesGenerator < Rails::Generators::NamedBase
|
7
7
|
desc "Add role strategy to a model"
|
8
|
+
|
9
|
+
# argument name
|
8
10
|
|
9
11
|
class_option :strategy, :type => :string, :aliases => "-s", :default => 'role_string',
|
10
12
|
:desc => "Role strategy to use (admin_flag, role_string, roles_string, role_strings, one_role, many_roles, roles_mask)"
|
@@ -15,9 +17,16 @@ module Mongoid
|
|
15
17
|
def apply_role_strategy
|
16
18
|
logger.add_logfile :logfile => logfile if logfile
|
17
19
|
logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
|
18
|
-
|
20
|
+
|
21
|
+
say "User model #{user_model_name} not found", :red if !has_model_file?(user_model_name)
|
22
|
+
|
23
|
+
insert_into_model user_model_name, :after => /include Mongoid::\w+/ do
|
19
24
|
insertion_text
|
20
|
-
end
|
25
|
+
end
|
26
|
+
|
27
|
+
unless read_model(:user) =~ /use_roles_strategy/
|
28
|
+
inject_into_file model_file(:user), "use_roles_strategy :#{strategy}\n\n", :before => "class"
|
29
|
+
end
|
21
30
|
end
|
22
31
|
|
23
32
|
protected
|
@@ -27,6 +36,14 @@ module Mongoid
|
|
27
36
|
|
28
37
|
use_orm :mongoid
|
29
38
|
|
39
|
+
def logfile
|
40
|
+
options[:logfile]
|
41
|
+
end
|
42
|
+
|
43
|
+
def user_model_name
|
44
|
+
name || 'User'
|
45
|
+
end
|
46
|
+
|
30
47
|
def orm
|
31
48
|
:mongoid
|
32
49
|
end
|
@@ -52,9 +69,14 @@ module Mongoid
|
|
52
69
|
end
|
53
70
|
|
54
71
|
def roles_statement
|
72
|
+
return '' if has_valid_roles_statement?
|
55
73
|
roles ? "valid_roles_are #{roles.join(', ')}" : ''
|
56
74
|
end
|
57
75
|
|
76
|
+
def has_valid_roles_statement?
|
77
|
+
!(read_model(user_model_name) =~ /valid_roles_are/).nil?
|
78
|
+
end
|
79
|
+
|
58
80
|
def insertion_text
|
59
81
|
%Q{include Roles::#{orm.to_s.camelize}
|
60
82
|
#{role_strategy_statement}
|
data/roles_mongoid.gemspec
CHANGED