roles_mongoid 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/generators/mongoid/roles/core_ext.rb +11 -0
- data/lib/generators/mongoid/roles/roles_generator.rb +24 -15
- data/roles_mongoid.gemspec +2 -1
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails3_artifactor'
|
2
2
|
require 'logging_assist'
|
3
|
+
require 'generators/mongoid/roles/core_ext'
|
3
4
|
|
4
5
|
module Mongoid
|
5
6
|
module Generators
|
@@ -20,30 +21,30 @@ module Mongoid
|
|
20
21
|
|
21
22
|
def apply_role_strategy
|
22
23
|
logger.add_logfile :logfile => logfile if logfile
|
23
|
-
logger.debug "apply_role_strategy for : #{strategy} in model #{
|
24
|
+
logger.debug "apply_role_strategy for : #{strategy} in model #{user_file}"
|
24
25
|
|
25
26
|
if !valid_strategy?
|
26
|
-
|
27
|
+
logger.error "Strategy #{strategy} is not currently supported, please try one of #{valid_strategies.join(', ')}"
|
27
28
|
end
|
28
29
|
|
29
|
-
if !has_model_file?(
|
30
|
-
|
30
|
+
if !has_model_file?(user_file)
|
31
|
+
logger.error "User model #{user_file} not found"
|
31
32
|
return
|
32
33
|
end
|
33
34
|
|
34
|
-
if !is_mongoid_model?(
|
35
|
-
|
35
|
+
if !is_mongoid_model?(user_file)
|
36
|
+
logger.error "User model #{user_file} is not a Mongoid Document"
|
36
37
|
return
|
37
38
|
end
|
38
39
|
|
39
40
|
begin
|
40
|
-
logger.debug "Trying to insert roles code into #{
|
41
|
+
logger.debug "Trying to insert roles code into #{user_file}"
|
41
42
|
|
42
|
-
insert_into_model
|
43
|
+
insert_into_model user_file, :after => /include Mongoid::\w+/ do
|
43
44
|
insertion_text
|
44
45
|
end
|
45
46
|
rescue Exception => e
|
46
|
-
logger.
|
47
|
+
logger.error "Error: #{e.message}"
|
47
48
|
end
|
48
49
|
|
49
50
|
copy_role_class if role_class_strategy?
|
@@ -56,8 +57,12 @@ module Mongoid
|
|
56
57
|
|
57
58
|
use_orm :mongoid
|
58
59
|
|
59
|
-
def
|
60
|
-
user_class.
|
60
|
+
def user_file
|
61
|
+
user_class.as_filename
|
62
|
+
end
|
63
|
+
|
64
|
+
def role_file
|
65
|
+
role_class.as_filename
|
61
66
|
end
|
62
67
|
|
63
68
|
def is_mongoid_model? name
|
@@ -80,13 +85,17 @@ module Mongoid
|
|
80
85
|
:mongoid
|
81
86
|
end
|
82
87
|
|
88
|
+
def orm_class
|
89
|
+
orm.to_s.camelize
|
90
|
+
end
|
91
|
+
|
83
92
|
def default_roles
|
84
93
|
[:admin, :guest]
|
85
94
|
end
|
86
95
|
|
87
96
|
def copy_role_class
|
88
|
-
logger.debug "
|
89
|
-
template 'role.rb', "app/models/#{
|
97
|
+
logger.debug "generating role model: #{role_file}"
|
98
|
+
template 'role.rb', "app/models/#{role_file}.rb"
|
90
99
|
end
|
91
100
|
|
92
101
|
def roles_to_add
|
@@ -102,7 +111,7 @@ module Mongoid
|
|
102
111
|
end
|
103
112
|
|
104
113
|
def strategy_option_arg
|
105
|
-
return ", :role_class =>
|
114
|
+
return ", :role_class => '#{role_class}'" if role_class_strategy? && role_class.to_s != 'Role'
|
106
115
|
''
|
107
116
|
end
|
108
117
|
|
@@ -120,7 +129,7 @@ module Mongoid
|
|
120
129
|
end
|
121
130
|
|
122
131
|
def insertion_text
|
123
|
-
%Q{include Roles::#{
|
132
|
+
%Q{include Roles::#{orm_class}
|
124
133
|
#{role_strategy_statement}
|
125
134
|
#{valid_roles_statement}}
|
126
135
|
end
|
data/roles_mongoid.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roles_mongoid}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.textile",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
+
"lib/generators/mongoid/roles/core_ext.rb",
|
28
29
|
"lib/generators/mongoid/roles/roles_generator.rb",
|
29
30
|
"lib/generators/mongoid/roles/templates/role.rb",
|
30
31
|
"lib/roles_mongoid.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -279,6 +279,7 @@ files:
|
|
279
279
|
- README.textile
|
280
280
|
- Rakefile
|
281
281
|
- VERSION
|
282
|
+
- lib/generators/mongoid/roles/core_ext.rb
|
282
283
|
- lib/generators/mongoid/roles/roles_generator.rb
|
283
284
|
- lib/generators/mongoid/roles/templates/role.rb
|
284
285
|
- lib/roles_mongoid.rb
|