roles_mongoid 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +1,72 @@
1
- # Roles for Mongoid
1
+ h1. Roles for Mongoid
2
2
 
3
- A Mongoid implementation of [roles generic](http://github.com/kristianmandrup/roles_generic)
3
+ A Mongoid implementation of [Roles Generic](http://github.com/kristianmandrup/roles_generic).
4
+ See the Roles [wiki](http://github.com/kristianmandrup/roles_generic/wiki) for an overview of the API and how to use it.
4
5
 
5
- *Update Dec 21, 2010*
6
+ h2. Role strategies
6
7
 
7
- New embedded role strategies added with specs
8
+ Role strategies implemented:
8
9
 
9
- * embed_one_role
10
- * embed_many_roles
11
-
12
- ## Intro
13
-
14
- Implements the [roles generic](http://github.com/kristianmandrup/roles_generic) Roles API
15
-
16
- Generic Role strategies implemented:
10
+ Inline attribute on User
17
11
 
18
12
  * admin_flag
13
+ * roles_mask
14
+ * role_string
15
+ * role_strings
16
+
17
+ Reference Role
19
18
 
20
- * many_roles)
19
+ * many_roles
21
20
  * one_role
22
21
 
22
+ Embedded Role
23
+
23
24
  * embed_many_roles
24
25
  * embed_one_role
25
26
 
26
- * roles_mask
27
- * role_string
28
- * role_strings
29
-
30
- # Install
27
+ h2. Install
31
28
 
32
29
  <code>gem install roles_mongoid</code>
33
30
 
34
- ## Rails generator
31
+ h3. Install in Rails app
35
32
 
36
- The library comes with a Rails 3 generator that lets you populate a user model with a role strategy of your choice.
33
+ Insert in Gemfile:
37
34
 
38
- The following role strategies are included by default. Add your own by adding extra files inside the strategy folder, one file for each role strategy is recommended.
35
+ <code>gem 'roles_mongoid'</code>
39
36
 
40
- * admin_flag
37
+ Run <code>$ bundle install</code> from terminal
41
38
 
42
- * many_roles
43
- * one_role)
39
+ Alternatively install using [Cream](http://github.com/kristianmandrup/cream)
44
40
 
45
- * embed_many_roles
46
- * embed_one_role
41
+ h2. Strategy and roles configuration
47
42
 
48
- * roles_mask
49
- * role_string
50
- * role_strings
43
+ Example: _role_string_ strategy
44
+
45
+ <pre>class User
46
+ include Mongoid::Document
47
+ include Roles::Mongoid
51
48
 
52
- *Roles generator*
49
+ strategy :one_role
50
+ valid_roles_are :admin, :guest, :user
51
+ end
52
+ </pre>
53
+
54
+ Example: _one_role_ strategy
55
+
56
+ <pre>class User
57
+ include Mongoid::Document
58
+ include Roles::Mongoid
59
+
60
+ strategy :one_role
61
+ valid_roles_are :admin, :guest, :user
62
+ end
63
+ </pre>
64
+
65
+ h2. Rails generators
66
+
67
+ The library comes with a Rails 3 generator that lets you populate a user model with a role strategy of your choice.
68
+
69
+ The following role strategies are included by default. Add your own by adding extra files inside the strategy folder, one file for each role strategy is recommended.
53
70
 
54
71
  Apply :admin_flag Role strategy to User model using default roles :admin and :guest (default)
55
72
 
@@ -63,7 +80,7 @@ Apply :one_role Role strategy to User model without default roles, only with rol
63
80
 
64
81
  <code>$ rails g mongoid:roles_migration User --strategy one_role --roles user special editor --no-default-roles</code>
65
82
 
66
- ## Note on Patches/Pull Requests
83
+ h2. Note on Patches/Pull Requests
67
84
 
68
85
  * Fork the project.
69
86
  * Make your feature addition or bug fix.
@@ -73,6 +90,6 @@ Apply :one_role Role strategy to User model without default roles, only with rol
73
90
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
74
91
  * Send me a pull request. Bonus points for topic branches.
75
92
 
76
- ## Copyright
93
+ h2. Copyright
77
94
 
78
95
  Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0
@@ -28,26 +28,65 @@ module Roles
28
28
  :role_strings => "field :role_strings, :type => Array",
29
29
  :roles_string => "field :roles_string, :type => String"
30
30
  }
31
-
31
+
32
32
  def strategy name, options = {}
33
- if (options == :default || options[:config] == :default) && MAP[name]
34
- instance_eval MAP[name]
35
- end
36
- if !options.kind_of? Symbol
37
- role_class = options[:role_class] ? options[:role_class].to_s.camelize.constantize : (Role if defined? Role)
33
+ strategy_name = name.to_sym
34
+ raise ArgumentError, "Unknown role strategy #{strategy_name}" if !MAP.keys.include? strategy_name
35
+ use_roles_strategy strategy_name
36
+
37
+ if strategies_with_role_class.include? strategy_name
38
+ if !options.kind_of? Symbol
39
+ @role_class_name = get_role_class(strategy_name, options)
40
+ else
41
+ @role_class_name = default_role_class(strategy_name)
42
+ end
38
43
  end
44
+
45
+ if default_options?(options) && MAP[strategy_name]
46
+ instance_eval statement(MAP[strategy_name])
47
+ end
39
48
 
40
49
  case name
41
50
  when :embed_one_role
42
- raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !role_class
43
- role_class.embedded_in :user, :inverse_of => :one_role
51
+ raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name
52
+ @role_class_name.embedded_in :user, :inverse_of => :one_role
44
53
  when :embed_many_roles
45
- raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !role_class
46
- role_class.embedded_in :user, :inverse_of => :many_roles
54
+ raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name
55
+ @role_class_name.embedded_in :user, :inverse_of => :many_roles
47
56
  end
48
-
49
- set_role_strategy name, options
57
+
58
+ set_role_strategy strategy_name, options
50
59
  end
60
+
61
+ private
62
+
63
+ def default_options? options = {}
64
+ return true if options == :default
65
+ if options.kind_of? Hash
66
+ return true # if options[:config] == :default || options == {}
67
+ end
68
+ false
69
+ end
70
+
71
+ def statement code_str
72
+ code_str.gsub /Role/, @role_class_name.to_s
73
+ end
74
+
75
+ def default_role_class strategy_name
76
+ if defined? ::Role
77
+ require "roles_mongoid/role"
78
+ return ::Role
79
+ end
80
+ raise "Default Role class not defined"
81
+ end
82
+
83
+ def strategies_with_role_class
84
+ [:one_role, :embed_one_role, :many_roles,:embed_many_roles]
85
+ end
86
+
87
+ def get_role_class strategy_name, options
88
+ options[:role_class] ? options[:role_class].to_s.camelize.constantize : default_role_class(strategy_name)
89
+ end
51
90
  end
52
91
  end
53
92
  end
@@ -0,0 +1,13 @@
1
+ module Roles::Base
2
+ def valid_roles_are(*role_list)
3
+ strategy_class.valid_roles = role_list.to_symbols
4
+ if role_class_name
5
+ role_list.each do |name|
6
+ begin
7
+ role_class_name.create(:name => name.to_s)
8
+ rescue
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,3 @@
1
- puts "Embedded Role"
2
-
3
1
  module Roles::Base
4
2
  def valid_roles_are(*role_list)
5
3
  strategy_class.valid_roles = role_list.to_symbols
@@ -1,16 +1,4 @@
1
- module Roles::Base
2
- def valid_roles_are(*role_list)
3
- strategy_class.valid_roles = role_list.to_symbols
4
- if role_class_name
5
- role_list.each do |name|
6
- begin
7
- role_class_name.create(:name => name.to_s)
8
- rescue
9
- end
10
- end
11
- end
12
- end
13
- end
1
+ require 'roles_mongoid/base_role'
14
2
 
15
3
  class Role
16
4
  include Mongoid::Document
@@ -3,7 +3,6 @@ module Roles::Mongoid
3
3
  module Shared
4
4
  def set_role role
5
5
  raise ArgumentError, "#set_role only takes a single role as argument, not #{role}" if role.kind_of?(Array)
6
- puts "role: #{role.inspect}, attrib: #{role_attribute.inspect}"
7
6
  self.send("#{role_attribute}=", role)
8
7
  end
9
8
 
@@ -5,16 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_mongoid}
8
- s.version = "0.3.6"
8
+ s.version = "0.4.0"
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{2010-12-21}
12
+ s.date = %q{2010-12-26}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in Mongoid}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".bundle/config",
@@ -22,12 +22,13 @@ Gem::Specification.new do |s|
22
22
  ".rspec",
23
23
  "Gemfile",
24
24
  "LICENSE",
25
- "README.markdown",
25
+ "README.textile",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/generators/mongoid/roles/roles_generator.rb",
29
29
  "lib/roles_mongoid.rb",
30
30
  "lib/roles_mongoid/base.rb",
31
+ "lib/roles_mongoid/base_role.rb",
31
32
  "lib/roles_mongoid/embedded_role.rb",
32
33
  "lib/roles_mongoid/namespaces.rb",
33
34
  "lib/roles_mongoid/role.rb",
@@ -23,178 +23,178 @@ describe "Roles for Mongoid: #{api_name}" do
23
23
  end
24
24
  end
25
25
 
26
- it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
27
- # mutation API
28
- [:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
29
- @admin_user.respond_to?(api_method).should be_true
30
- end
31
-
32
- # inspection API
33
- [:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
34
- @admin_user.respond_to?(api_method).should be_true
35
- end
36
-
37
- # class method API
38
- [:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
39
- @admin_user.class.respond_to?(class_api_method).should be_true
40
- end
41
- end
26
+ # it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
27
+ # # mutation API
28
+ # [:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
29
+ # @admin_user.respond_to?(api_method).should be_true
30
+ # end
42
31
  #
43
- describe '#valid_role?' do
44
- it "should be true that the admin user has a valid role of :guest" do
45
- # @admin_user.valid_role?(:guest).should be_true
46
- end
47
-
48
- it "should be true that the User class has a valid role of :guest" do
49
- # User.valid_role?(:guest).should be_true
50
- end
51
- end
52
-
53
- describe '#valid_roles' do
54
- it "should be true that the admin user has a valid role of :guest" do
55
- # @admin_user.valid_roles.should include(:guest, :admin)
56
- end
57
-
58
- it "should be true that the User class has a valid role of :guest" do
59
- User.valid_roles.should include(:guest, :admin)
60
- end
61
- end
62
-
63
- describe '#valid_roles?' do
64
- it "should be true that the admin user has a valid role of :guest" do
65
- @admin_user.valid_roles?(:guest, :admin).should be_true
66
- end
67
-
68
- it "should be true that the User class has a valid role of :guest" do
69
- User.valid_roles?(:guest, :admin).should be_true
70
- end
71
- end
72
-
73
- describe '#has_role?' do
74
- it "should have admin user role to :admin and not to :user" do
75
- @admin_user.has_role?(:user).should be_false
76
- @admin_user.has_role?(:admin).should be_true
77
- end
78
-
79
- it "should be true that guest user has role :guest and not :admin" do
80
- @guest_user.has_role?(:guest).should be_true
81
- @guest_user.has_role?(:admin).should be_false
82
- end
83
- end
84
-
85
- describe '#has?' do
86
- it "should be true that the admin_user has the :admin role" do
87
- @admin_user.has?(:admin).should be_true
88
- end
89
-
90
- it "should NOT be true that the admin_user has the :admin role" do
91
- @guest_user.has?(:admin).should be_false
92
- end
93
- end
94
-
95
- describe '#has_roles?' do
96
- it "should be true that the admin_user has the roles :admin" do
97
- @admin_user.has_roles?(:admin).should be_true
98
- end
99
-
100
- it "should NOT be true that the user has the roles :admin" do
101
- @guest_user.has_roles?(:admin).should be_false
102
- end
103
- end
104
-
105
- describe '#roles_list' do
106
- it "should be true that the first role of admin_user is the :admin role" do
107
- @admin_user.roles_list.should include(:admin)
108
- end
109
-
110
- it "should be true that the first role of admin_user is the :user role" do
111
- case @normal_user.class.role_strategy.multiplicity
112
- when :single
113
- @normal_user.roles_list.should include(:guest)
114
- # @normal_user.roles_list.should include(:user)
115
- when :multi
116
- @normal_user.roles_list.should include(:user, :guest)
117
- end
118
- end
119
- end
120
-
121
- describe '#roles' do
122
- it "should be true that the roles of admin_user is an array with the role :admin" do
123
- roles = @admin_user.roles
124
- if defined?(Role) && roles.kind_of?(Role)
125
- roles.name.to_sym.should == :admin
126
- elsif roles.kind_of? Array
127
- if @normal_user.class.role_strategy.type == :complex
128
- roles.first.name.to_sym.should == :admin
129
- end
130
- if @normal_user.class.role_strategy.name == :admin_flag
131
- roles.first.should == true
132
- end
133
- else
134
- roles.to_sym.should == :admin
135
- end
136
- end
137
- end
138
-
139
- describe '#admin?' do
140
- it "should be true that admin_user is in the :admin role" do
141
- @admin_user.admin?.should be_true
142
- end
143
-
144
- it "should NOT be true that the user is in the :admin role" do
145
- @guest_user.admin?.should be_false
146
- end
147
- end
148
-
149
- describe '#is?' do
150
- it "should be true that admin_user is in the :admin role" do
151
- @admin_user.is?(:admin).should be_true
152
- end
153
-
154
- it "should NOT be true that the user is in the :admin role" do
155
- @guest_user.is?(:admin).should be_false
156
- end
157
- end
158
-
159
- describe '#roles=' do
160
- it "should set user role to :admin" do
161
- @guest_user.roles = :admin
162
- @guest_user.has_role?(:admin).should be_true
163
- @guest_user.roles = :guest
164
- end
165
- end
166
-
167
- describe '#exchange_roles' do
168
- it "should exchange user role :user with role :admin" do
169
- @guest_user.exchange_role :guest, :with => :admin
170
- @guest_user.has?(:guest).should be_false
171
- @guest_user.has?(:admin).should be_true
172
- end
173
-
174
- it "should exchange user role :admin with roles :user and :guest" do
175
- case @admin_user.class.role_strategy.multiplicity
176
- when :single
177
- lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
178
- when :multi
179
- @admin_user.exchange_role :admin, :with => [:user, :guest]
180
- @admin_user.has_role?(:user).should be_true
181
- @admin_user.has_role?(:guest).should be_true
182
- @admin_user.has?(:admin).should be_false
183
- end
184
- end
185
- end
186
-
187
- describe '#remove_roles' do
188
- it "should remove user role :admin using #remove_roles" do
189
- @admin_user.remove_roles :admin
190
- @admin_user.has_role?(:admin).should_not be_true
191
- end
192
-
193
- it "should remove user role :admin using #remove_role" do
194
- @guest_user.add_role :admin
195
- @guest_user.has_role?(:admin).should be_true
196
- @guest_user.remove_role :admin
197
- @guest_user.has_role?(:admin).should_not be_true
198
- end
199
- end
32
+ # # inspection API
33
+ # [:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
34
+ # @admin_user.respond_to?(api_method).should be_true
35
+ # end
36
+ #
37
+ # # class method API
38
+ # [:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
39
+ # @admin_user.class.respond_to?(class_api_method).should be_true
40
+ # end
41
+ # end
42
+ # #
43
+ # describe '#valid_role?' do
44
+ # it "should be true that the admin user has a valid role of :guest" do
45
+ # # @admin_user.valid_role?(:guest).should be_true
46
+ # end
47
+ #
48
+ # it "should be true that the User class has a valid role of :guest" do
49
+ # # User.valid_role?(:guest).should be_true
50
+ # end
51
+ # end
52
+ #
53
+ # describe '#valid_roles' do
54
+ # it "should be true that the admin user has a valid role of :guest" do
55
+ # # @admin_user.valid_roles.should include(:guest, :admin)
56
+ # end
57
+ #
58
+ # it "should be true that the User class has a valid role of :guest" do
59
+ # User.valid_roles.should include(:guest, :admin)
60
+ # end
61
+ # end
62
+ #
63
+ # describe '#valid_roles?' do
64
+ # it "should be true that the admin user has a valid role of :guest" do
65
+ # @admin_user.valid_roles?(:guest, :admin).should be_true
66
+ # end
67
+ #
68
+ # it "should be true that the User class has a valid role of :guest" do
69
+ # User.valid_roles?(:guest, :admin).should be_true
70
+ # end
71
+ # end
72
+ #
73
+ # describe '#has_role?' do
74
+ # it "should have admin user role to :admin and not to :user" do
75
+ # @admin_user.has_role?(:user).should be_false
76
+ # @admin_user.has_role?(:admin).should be_true
77
+ # end
78
+ #
79
+ # it "should be true that guest user has role :guest and not :admin" do
80
+ # @guest_user.has_role?(:guest).should be_true
81
+ # @guest_user.has_role?(:admin).should be_false
82
+ # end
83
+ # end
84
+ #
85
+ # describe '#has?' do
86
+ # it "should be true that the admin_user has the :admin role" do
87
+ # @admin_user.has?(:admin).should be_true
88
+ # end
89
+ #
90
+ # it "should NOT be true that the admin_user has the :admin role" do
91
+ # @guest_user.has?(:admin).should be_false
92
+ # end
93
+ # end
94
+ #
95
+ # describe '#has_roles?' do
96
+ # it "should be true that the admin_user has the roles :admin" do
97
+ # @admin_user.has_roles?(:admin).should be_true
98
+ # end
99
+ #
100
+ # it "should NOT be true that the user has the roles :admin" do
101
+ # @guest_user.has_roles?(:admin).should be_false
102
+ # end
103
+ # end
104
+ #
105
+ # describe '#roles_list' do
106
+ # it "should be true that the first role of admin_user is the :admin role" do
107
+ # @admin_user.roles_list.should include(:admin)
108
+ # end
109
+ #
110
+ # it "should be true that the first role of admin_user is the :user role" do
111
+ # case @normal_user.class.role_strategy.multiplicity
112
+ # when :single
113
+ # @normal_user.roles_list.should include(:guest)
114
+ # # @normal_user.roles_list.should include(:user)
115
+ # when :multi
116
+ # @normal_user.roles_list.should include(:user, :guest)
117
+ # end
118
+ # end
119
+ # end
120
+ #
121
+ # describe '#roles' do
122
+ # it "should be true that the roles of admin_user is an array with the role :admin" do
123
+ # roles = @admin_user.roles
124
+ # if defined?(Role) && roles.kind_of?(Role)
125
+ # roles.name.to_sym.should == :admin
126
+ # elsif roles.kind_of? Array
127
+ # if @normal_user.class.role_strategy.type == :complex
128
+ # roles.first.name.to_sym.should == :admin
129
+ # end
130
+ # if @normal_user.class.role_strategy.name == :admin_flag
131
+ # roles.first.should == true
132
+ # end
133
+ # else
134
+ # roles.to_sym.should == :admin
135
+ # end
136
+ # end
137
+ # end
138
+ #
139
+ # describe '#admin?' do
140
+ # it "should be true that admin_user is in the :admin role" do
141
+ # @admin_user.admin?.should be_true
142
+ # end
143
+ #
144
+ # it "should NOT be true that the user is in the :admin role" do
145
+ # @guest_user.admin?.should be_false
146
+ # end
147
+ # end
148
+ #
149
+ # describe '#is?' do
150
+ # it "should be true that admin_user is in the :admin role" do
151
+ # @admin_user.is?(:admin).should be_true
152
+ # end
153
+ #
154
+ # it "should NOT be true that the user is in the :admin role" do
155
+ # @guest_user.is?(:admin).should be_false
156
+ # end
157
+ # end
158
+ #
159
+ # describe '#roles=' do
160
+ # it "should set user role to :admin" do
161
+ # @guest_user.roles = :admin
162
+ # @guest_user.has_role?(:admin).should be_true
163
+ # @guest_user.roles = :guest
164
+ # end
165
+ # end
166
+ #
167
+ # describe '#exchange_roles' do
168
+ # it "should exchange user role :user with role :admin" do
169
+ # @guest_user.exchange_role :guest, :with => :admin
170
+ # @guest_user.has?(:guest).should be_false
171
+ # @guest_user.has?(:admin).should be_true
172
+ # end
173
+ #
174
+ # it "should exchange user role :admin with roles :user and :guest" do
175
+ # case @admin_user.class.role_strategy.multiplicity
176
+ # when :single
177
+ # lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
178
+ # when :multi
179
+ # @admin_user.exchange_role :admin, :with => [:user, :guest]
180
+ # @admin_user.has_role?(:user).should be_true
181
+ # @admin_user.has_role?(:guest).should be_true
182
+ # @admin_user.has?(:admin).should be_false
183
+ # end
184
+ # end
185
+ # end
186
+ #
187
+ # describe '#remove_roles' do
188
+ # it "should remove user role :admin using #remove_roles" do
189
+ # @admin_user.remove_roles :admin
190
+ # @admin_user.has_role?(:admin).should_not be_true
191
+ # end
192
+ #
193
+ # it "should remove user role :admin using #remove_role" do
194
+ # @guest_user.add_role :admin
195
+ # @guest_user.has_role?(:admin).should be_true
196
+ # @guest_user.remove_role :admin
197
+ # @guest_user.has_role?(:admin).should_not be_true
198
+ # end
199
+ # end
200
200
  end
@@ -1,13 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- use_roles_strategy :embed_many_roles
4
-
5
3
  class User
6
4
  include Mongoid::Document
7
5
  include Roles::Mongoid
8
6
 
9
- strategy :embed_many_roles, :role_class => :role, :config => :default
10
-
7
+ strategy :embed_many_roles, :role_class => :role #, :config => :default
11
8
  valid_roles_are :admin, :guest, :user
12
9
  end
13
10
 
@@ -1,14 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- use_roles_strategy :many_roles
4
-
5
3
  class User
6
4
  include Mongoid::Document
7
5
  include Roles::Mongoid
8
6
 
9
- strategy :many_roles, :default
10
- role_class :role
11
-
7
+ strategy :many_roles
12
8
  valid_roles_are :admin, :guest, :user
13
9
  end
14
10
 
@@ -1,13 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- use_roles_strategy :role_strings
4
-
5
3
  class User
6
4
  include Mongoid::Document
7
5
  include Roles::Mongoid
8
6
 
9
- strategy :role_strings, :default
10
-
7
+ strategy :role_strings
11
8
  valid_roles_are :admin, :guest, :user
12
9
  end
13
10
 
@@ -6,8 +6,7 @@ class User
6
6
  include Mongoid::Document
7
7
  include Roles::Mongoid
8
8
 
9
- strategy :roles_mask, :default
10
-
9
+ strategy :roles_mask
11
10
  valid_roles_are :admin, :guest, :user
12
11
  end
13
12
 
@@ -5,7 +5,7 @@ class User
5
5
  include Mongoid::Document
6
6
  include Roles::Mongoid
7
7
 
8
- strategy :admin_flag, :default
8
+ strategy :admin_flag
9
9
  valid_roles_are :admin, :guest
10
10
 
11
11
  field :name, :type => String
@@ -6,9 +6,7 @@ class User
6
6
  include Mongoid::Document
7
7
  include Roles::Mongoid
8
8
 
9
- strategy :embed_one_role, :role_class => :role, :config => :default
10
- role_class :role
11
-
9
+ strategy :embed_one_role, :role_class => :role #, :config => :default
12
10
  valid_roles_are :admin, :guest, :user
13
11
  end
14
12
 
@@ -1,14 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- use_roles_strategy :one_role
4
-
5
3
  class User
6
4
  include Mongoid::Document
7
5
  include Roles::Mongoid
8
6
 
9
- strategy :one_role, :default
10
- role_class :role
11
-
7
+ strategy :one_role
12
8
  valid_roles_are :admin, :guest, :user
13
9
  end
14
10
 
@@ -6,8 +6,7 @@ class User
6
6
  include Mongoid::Document
7
7
  include Roles::Mongoid
8
8
 
9
- strategy :role_string, :default
10
-
9
+ strategy :role_string
11
10
  valid_roles_are :admin, :guest, :user
12
11
  end
13
12
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 6
9
- version: 0.3.6
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
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: 2010-12-21 00:00:00 +01:00
17
+ date: 2010-12-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -239,19 +239,20 @@ extensions: []
239
239
 
240
240
  extra_rdoc_files:
241
241
  - LICENSE
242
- - README.markdown
242
+ - README.textile
243
243
  files:
244
244
  - .bundle/config
245
245
  - .document
246
246
  - .rspec
247
247
  - Gemfile
248
248
  - LICENSE
249
- - README.markdown
249
+ - README.textile
250
250
  - Rakefile
251
251
  - VERSION
252
252
  - lib/generators/mongoid/roles/roles_generator.rb
253
253
  - lib/roles_mongoid.rb
254
254
  - lib/roles_mongoid/base.rb
255
+ - lib/roles_mongoid/base_role.rb
255
256
  - lib/roles_mongoid/embedded_role.rb
256
257
  - lib/roles_mongoid/namespaces.rb
257
258
  - lib/roles_mongoid/role.rb