roles_mongo_mapper 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/generators/mongo_mapper/roles/roles_generator.rb +26 -15
- data/roles_mongo_mapper.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -3,32 +3,43 @@ require 'logging_assist'
|
|
3
3
|
|
4
4
|
module MongoMapper
|
5
5
|
module Generators
|
6
|
-
class RolesGenerator < Rails::Generators::
|
7
|
-
desc "Add role strategy to a model"
|
6
|
+
class RolesGenerator < Rails::Generators::Base
|
7
|
+
desc "Add role strategy to a MongoMapper User model"
|
8
|
+
|
9
|
+
argument :user_class, :type => :string, :default => 'User', :desc => "User class name"
|
8
10
|
|
9
|
-
class_option :strategy,
|
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)"
|
11
13
|
|
12
|
-
|
13
|
-
class_option :roles, :type => :array, :default => [],
|
14
|
-
class_option :role_class, :type => :string, :aliases => "-rc",
|
14
|
+
|
15
|
+
class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
|
16
|
+
class_option :role_class, :type => :string, :aliases => "-rc", :default => 'Role', :desc => "Role class"
|
17
|
+
|
18
|
+
class_option :logfile, :type => :string, :aliases => "-l", :default => nil, :desc => "Logfile location"
|
15
19
|
|
16
20
|
def apply_role_strategy
|
17
21
|
logger.add_logfile :logfile => logfile if logfile
|
18
|
-
logger.debug "apply_role_strategy for : #{strategy} in model #{
|
22
|
+
logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
|
19
23
|
|
20
24
|
if !valid_strategy?
|
21
25
|
say "Strategy '#{strategy}' is not valid. The valid strategies are: #{valid_strategies.join(', ')}", :red
|
22
26
|
return
|
23
27
|
end
|
24
28
|
|
25
|
-
if !has_model_file?(
|
26
|
-
say "User model #{
|
29
|
+
if !has_model_file?(user_class)
|
30
|
+
say "User model #{user_class} not found", :red
|
27
31
|
return
|
28
32
|
end
|
29
33
|
|
34
|
+
if !is_mongo_mapper_model?(user_class)
|
35
|
+
say "User model #{user_class} is not a Mongo Mapper Document", :red
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
30
39
|
begin
|
31
|
-
|
40
|
+
logger.debug "Trying to insert roles code into #{user_class}"
|
41
|
+
|
42
|
+
insert_into_model user_class, :after => /include MongoMapper::\w+/ do
|
32
43
|
insertion_text
|
33
44
|
end
|
34
45
|
rescue Exception => e
|
@@ -45,6 +56,10 @@ module MongoMapper
|
|
45
56
|
|
46
57
|
use_orm :mongo_mapper
|
47
58
|
|
59
|
+
def is_mongo_mapper_model? name
|
60
|
+
read_model(name) =~ /include MongoMapper::\w+/
|
61
|
+
end
|
62
|
+
|
48
63
|
def role_class_strategy?
|
49
64
|
# :embed_one_role, :embed_many_roles
|
50
65
|
[:one_role, :many_roles].include? strategy.to_sym
|
@@ -69,10 +84,6 @@ module MongoMapper
|
|
69
84
|
options[:logfile]
|
70
85
|
end
|
71
86
|
|
72
|
-
def user_model_name
|
73
|
-
name || 'User'
|
74
|
-
end
|
75
|
-
|
76
87
|
def orm
|
77
88
|
:mongo_mapper
|
78
89
|
end
|
@@ -108,7 +119,7 @@ module MongoMapper
|
|
108
119
|
end
|
109
120
|
|
110
121
|
def has_valid_roles_statement?
|
111
|
-
!(read_model(
|
122
|
+
!(read_model(user_class) =~ /valid_roles_are/).nil?
|
112
123
|
end
|
113
124
|
|
114
125
|
def insertion_text
|
data/roles_mongo_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roles_mongo_mapper}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
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"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-06}
|
13
13
|
s.description = %q{Makes it easy to set a role strategy on your User model in MongoMapper}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-06 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|