rolify 5.1.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.hakiri.yml +1 -0
  3. data/.travis.yml +36 -68
  4. data/Appraisals +34 -21
  5. data/CHANGELOG.rdoc +28 -8
  6. data/CONTRIBUTORS +9 -0
  7. data/Gemfile +3 -2
  8. data/LICENSE +1 -1
  9. data/README.md +44 -12
  10. data/Rakefile +1 -0
  11. data/gemfiles/activerecord_4.gemfile +9 -7
  12. data/gemfiles/activerecord_5.gemfile +16 -15
  13. data/gemfiles/activerecord_6.gemfile +28 -0
  14. data/gemfiles/mongoid_5.gemfile +8 -6
  15. data/gemfiles/mongoid_6.gemfile +20 -0
  16. data/gemfiles/mongoid_7.gemfile +21 -0
  17. data/lib/generators/active_record/rolify_generator.rb +13 -15
  18. data/lib/generators/active_record/templates/migration.rb +2 -3
  19. data/lib/generators/active_record/templates/model.rb +15 -0
  20. data/lib/generators/rolify/templates/initializer.rb +4 -1
  21. data/lib/rolify/adapters/active_record/resource_adapter.rb +3 -3
  22. data/lib/rolify/adapters/active_record/role_adapter.rb +3 -9
  23. data/lib/rolify/role.rb +1 -1
  24. data/lib/rolify/version.rb +1 -1
  25. data/lib/rolify.rb +3 -3
  26. data/rolify.gemspec +5 -4
  27. data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +100 -3
  28. data/spec/rolify/utils_spec.rb +19 -0
  29. data/spec/spec_helper.rb +2 -3
  30. data/spec/support/adapters/{mongoid_3.yml → mongoid_6.yml} +2 -2
  31. data/spec/support/adapters/{mongoid_4.yml → mongoid_7.yml} +2 -2
  32. metadata +21 -21
  33. data/gemfiles/Gemfile.rails-3.2 +0 -27
  34. data/gemfiles/Gemfile.rails-4.0 +0 -33
  35. data/gemfiles/Gemfile.rails-4.1 +0 -37
  36. data/gemfiles/activerecord_3.gemfile +0 -19
  37. data/gemfiles/mongoid_3.gemfile +0 -19
  38. data/gemfiles/mongoid_4.gemfile +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8b81efc86ee3d4c660521e8b8cb7d1a5045b2ce7
4
- data.tar.gz: 84f19deb5072b9d46dcade6c8d5db085dd8cfb60
2
+ SHA256:
3
+ metadata.gz: 63187a09a4130c5a7f1066f306783ac5c2fba4e54d5f7130e4b60bdc921b7834
4
+ data.tar.gz: f66383e7b30ead36d1f2dac277cb473dc41479db4656a4bea0ac85f6c6253f69
5
5
  SHA512:
6
- metadata.gz: d0209a0003ff41826654b23c1ebd6eeb556aef5d8e6554dd86a63362e82a69cc624abdc903063d65f4ab706a42a4c908cb52662c6db9cec1a8a38725f4274afe
7
- data.tar.gz: 8aee6f2b0fa61dfe9c04aa42c2a496b7b907cb74f44b4c542a6b0587f46686085f5a30457e4168ba1485ed24eb3dd089e17e99a66d86da21e8c724767a2bf5d1
6
+ metadata.gz: 6e212c338c8f11662d4bf7f267ae4ecf7e9a4206667cf051053cbaf55b72bd9ba08f7022aed3f85737e29919c3b045129bdec8dfb2922dcb1544232583ce6fcd
7
+ data.tar.gz: e0d2c815832045141b1be4ff76a419704785d57e7195b9c18cafa35885267a4cecd3cf9b11ce7952192317d47ae57115d4831860694227aceb072ac56e5ed9ad
data/.hakiri.yml ADDED
@@ -0,0 +1 @@
1
+ dependency_source: gemspec_file
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
- sudo: false
3
2
 
4
3
  before_install:
5
4
  - gem update --system
@@ -8,80 +7,49 @@ before_install:
8
7
 
9
8
  script: bundle exec rake
10
9
 
11
- matrix:
12
- include:
13
- - rvm: 2.3.0
14
- gemfile: gemfiles/activerecord_3.gemfile
15
- env: ADAPTER=active_record
16
- - rvm: 2.2.4
17
- gemfile: gemfiles/activerecord_3.gemfile
18
- env: ADAPTER=active_record
19
- - rvm: 2.1.8
20
- gemfile: gemfiles/activerecord_3.gemfile
21
- env: ADAPTER=active_record
22
- - rvm: 2.0.0
23
- gemfile: gemfiles/activerecord_3.gemfile
24
- env: ADAPTER=active_record
10
+ after_success:
11
+ - bundle exec codeclimate-test-reporter
25
12
 
26
- - rvm: 2.3.0
27
- gemfile: gemfiles/activerecord_4.gemfile
28
- env: ADAPTER=active_record
29
- - rvm: 2.2.4
30
- gemfile: gemfiles/activerecord_4.gemfile
31
- env: ADAPTER=active_record
32
- - rvm: 2.1.8
33
- gemfile: gemfiles/activerecord_4.gemfile
34
- env: ADAPTER=active_record
35
- - rvm: 2.0.0
36
- gemfile: gemfiles/activerecord_4.gemfile
37
- env: ADAPTER=active_record
38
-
39
- - rvm: 2.3.0
40
- gemfile: gemfiles/activerecord_5.gemfile
41
- env: ADAPTER=active_record
42
- - rvm: 2.2.4
43
- gemfile: gemfiles/activerecord_5.gemfile
44
- env: ADAPTER=active_record
13
+ rvm:
14
+ - 2.7.0
15
+ - 2.6.3
16
+ - 2.5.5
17
+ - 2.4.6
18
+ - 2.3.8
45
19
 
46
- - rvm: 2.3.0
47
- gemfile: gemfiles/mongoid_3.gemfile
48
- env: ADAPTER=mongoid
49
- - rvm: 2.2.4
50
- gemfile: gemfiles/mongoid_3.gemfile
51
- env: ADAPTER=mongoid
52
- - rvm: 2.1.8
53
- gemfile: gemfiles/mongoid_3.gemfile
54
- env: ADAPTER=mongoid
55
- - rvm: 2.0.0
56
- gemfile: gemfiles/mongoid_3.gemfile
57
- env: ADAPTER=mongoid
20
+ gemfile:
21
+ - gemfiles/activerecord_4.gemfile
22
+ - gemfiles/activerecord_5.gemfile
23
+ - gemfiles/activerecord_6.gemfile
24
+ - gemfiles/mongoid_5.gemfile
25
+ - gemfiles/mongoid_6.gemfile
26
+ - gemfiles/mongoid_7.gemfile
58
27
 
59
- - rvm: 2.3.0
60
- gemfile: gemfiles/mongoid_4.gemfile
61
- env: ADAPTER=mongoid
62
- - rvm: 2.2.4
63
- gemfile: gemfiles/mongoid_4.gemfile
64
- env: ADAPTER=mongoid
65
- - rvm: 2.1.8
66
- gemfile: gemfiles/mongoid_4.gemfile
67
- env: ADAPTER=mongoid
68
- - rvm: 2.0.0
69
- gemfile: gemfiles/mongoid_4.gemfile
70
- env: ADAPTER=mongoid
28
+ env:
29
+ - ADAPTER=active_record
30
+ - ADAPTER=mongoid
71
31
 
72
- - rvm: 2.3.0
73
- gemfile: gemfiles/mongoid_5.gemfile
74
- env: ADAPTER=mongoid
75
- - rvm: 2.2.4
76
- gemfile: gemfiles/mongoid_5.gemfile
32
+ matrix:
33
+ exclude:
34
+ - gemfile: gemfiles/activerecord_4.gemfile
77
35
  env: ADAPTER=mongoid
78
- - rvm: 2.1.8
79
- gemfile: gemfiles/mongoid_5.gemfile
36
+ - gemfile: gemfiles/activerecord_5.gemfile
80
37
  env: ADAPTER=mongoid
81
- - rvm: 2.0.0
82
- gemfile: gemfiles/mongoid_5.gemfile
38
+ - gemfile: gemfiles/activerecord_6.gemfile
83
39
  env: ADAPTER=mongoid
84
-
40
+ - gemfile: gemfiles/activerecord_6.gemfile
41
+ rvm: 2.4.6
42
+ - gemfile: gemfiles/activerecord_6.gemfile
43
+ rvm: 2.3.8
44
+ - gemfile: gemfiles/mongoid_5.gemfile
45
+ env: ADAPTER=active_record
46
+ - gemfile: gemfiles/mongoid_6.gemfile
47
+ env: ADAPTER=active_record
48
+ - gemfile: gemfiles/mongoid_7.gemfile
49
+ env: ADAPTER=active_record
50
+ allow_failures:
51
+ - gemfile: gemfiles/mongoid_6.gemfile
52
+ - gemfile: gemfiles/mongoid_7.gemfile
85
53
 
86
54
  services: mongodb
87
55
 
data/Appraisals CHANGED
@@ -1,41 +1,54 @@
1
- appraise 'mongoid-3' do
2
- gem "mongoid", "~> 3"
3
- gem "bson_ext", :platform => "ruby"
4
- end
5
-
6
- appraise 'mongoid-4' do
7
- gem "mongoid", "~> 4"
8
- gem "bson_ext", :platform => "ruby"
9
- end
10
-
11
1
  appraise 'mongoid-5' do
12
2
  gem "mongoid", "~> 5"
13
- gem "bson_ext", :platform => "ruby"
3
+ gem "bson_ext", "1.5.1"
4
+ gem 'bigdecimal', '1.4.2'
14
5
  end
15
6
 
16
- appraise 'activerecord-3' do
17
- gem "sqlite3", :platform => "ruby"
18
- gem "activerecord", ">= 3.2.0", :require => "active_record"
7
+ appraise 'mongoid-6' do
8
+ gem "mongoid", "~> 6"
9
+ gem "bson_ext", "1.5.1"
10
+ end
11
+
12
+ appraise 'mongoid-7' do
13
+ gem "mongoid", "~> 7"
14
+ gem "bson_ext", "1.5.1"
15
+ gem "railties", "5.2.4.1"
19
16
  end
20
17
 
21
18
  appraise 'activerecord-4' do
22
- gem "sqlite3", :platform => "ruby"
23
- gem "activerecord", ">= 4.2.5", :require => "active_record"
19
+ gem "sqlite3", "~> 1.3.6"
20
+ gem "activerecord", "~> 4.2.11", :require => "active_record"
21
+ gem 'bigdecimal', '1.4.2'
24
22
  end
25
23
 
26
24
  appraise 'activerecord-5' do
27
- gem "sqlite3", :platform => "ruby"
28
- gem "activerecord", ">= 5.0.0.beta", :require => "active_record"
25
+ gem "sqlite3", "~> 1.3.6"
26
+ gem "activerecord", "~> 5.2.4", :require => "active_record"
29
27
 
30
28
  # Ammeter dependencies:
31
- gem "actionpack", ">= 5.0.0.beta2"
32
- gem "activemodel", ">= 5.0.0.beta2"
33
- gem "railties", ">= 5.0.0.beta2"
29
+ gem "actionpack", "~> 5.2.4"
30
+ gem "activemodel", "~> 5.2.4"
31
+ gem "railties", "~> 5.2.4"
34
32
 
35
33
  gem 'rspec-rails' , github: 'rspec/rspec-rails'
36
34
  gem 'rspec-core' , github: 'rspec/rspec-core'
37
35
  gem 'rspec-expectations', github: 'rspec/rspec-expectations'
38
36
  gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
39
37
  gem 'rspec-support' , github: 'rspec/rspec-support'
38
+ end
39
+
40
+ appraise 'activerecord-6' do
41
+ gem "sqlite3", "~> 1.4", :platform => "ruby"
42
+ gem "activerecord", ">= 6.0.0", :require => "active_record"
40
43
 
44
+ # Ammeter dependencies:
45
+ gem "actionpack", ">= 6.0.0"
46
+ gem "activemodel", ">= 6.0.0"
47
+ gem "railties", ">= 6.0.0"
48
+
49
+ gem 'rspec-rails' , github: 'rspec/rspec-rails'
50
+ gem 'rspec-core' , github: 'rspec/rspec-core'
51
+ gem 'rspec-expectations', github: 'rspec/rspec-expectations'
52
+ gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
53
+ gem 'rspec-support' , github: 'rspec/rspec-support'
41
54
  end
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,23 @@
1
+ = 5.3.0 (June 1, 2020)
2
+
3
+ 5.3.0 will be the last version to support Ruby < 2.5 and Rails < 5.2. Support for these will be dropped in the next major release.
4
+
5
+ * Fix deprecation warning in Ruby 2.7
6
+ * Add Rails 6 support to migration generator
7
+ * Significant ActiveRecord performance improvements to <tt>add_role</tt> and <tt>without_role</tt>
8
+ * Mongoid fix and performance improvement and to <tt>roles_name</tt>
9
+ * Make it safe to call <tt>Thing.with_role(:admin, user)</tt> with new record
10
+
11
+ = 5.2.0 (Dec 14, 2017)
12
+ * Fix regression in generator around belongs_to options compatibility
13
+ * Update version of database_cleaner
14
+ * Update initializer.rb to include the remove_role_if_empty option and description
15
+ * Allow inverse_of option on rolify method
16
+ * Fix the code-climate-reporter issue that's causing travis to fail
17
+ * Remove a separate index for the name column
18
+ * Fix migration generator for AR 5.x
19
+ * Fixed ambiguous column error
20
+
1
21
  = 5.1.0 (Mar 19, 2016)
2
22
  * Rails 5 Support (thanks @lorefnon)
3
23
  * Fix user handling in generator (thanks @lorefnon)
@@ -116,7 +136,7 @@
116
136
  * fixed a backward incompatible change introduced in Rails 3.2 release (<tt>find_or_create_by_* generated methods</tt>)
117
137
 
118
138
  = 2.2 (Jan 18, 2012)
119
- * fixed a bug in the initializer file regarding dynamic shortcuts
139
+ * fixed a bug in the initializer file regarding dynamic shortcuts
120
140
 
121
141
  = 2.1 (Nov 30, 2011)
122
142
  * added syntactic sugar: <tt>grant</tt> and <tt>revoke</tt> are aliases for <tt>has_role</tt> and <tt>has_no_role</tt>
@@ -157,8 +177,8 @@
157
177
 
158
178
  = 1.0 (Aug 25, 2011)
159
179
  * added a new parameter to disable dynamic shortcut methods due to potential incompatibility with other gems using method_missing with the same pattern
160
- * add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
161
- * use the generator command with a third parameter:
180
+ * add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
181
+ * use the generator command with a third parameter:
162
182
  * <tt>rails g rolify:role Role User false</tt>
163
183
  * removed the railtie as it created more problems than it solved
164
184
  * code refactoring to do some speed improvements and code clean up
@@ -167,16 +187,16 @@
167
187
  * rolify is now on travis-ci to monitor build status
168
188
 
169
189
  = 0.7 (June 20, 2011)
170
- * added a method_missing to catch newly created role outside the current ruby process (i.e. dynamic shortcut methods are not defined within this process)
171
- * dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
172
- * check if the role actually exists in the database before defining the new method
190
+ * added a method_missing to catch newly created role outside the current ruby process (i.e. dynamic shortcut methods are not defined within this process)
191
+ * dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
192
+ * check if the role actually exists in the database before defining the new method
173
193
  * first call is slower due to method_missing but next calls are fast
174
194
  * avoid strange bugs when spawning many ruby processes as the dynamic shortcut methods were only defined in the process that used the <tt>has_role</tt> command
175
195
 
176
196
  = 0.6 (June 19, 2011)
177
197
  * custom User and Role class names support
178
198
  * can now use other class names for Role and User classes
179
- * fixed generators and templates
199
+ * fixed generators and templates
180
200
  * join table is explicitly set to avoid alphabetical order issue
181
201
  * created a new railtie to load the dynamic shortcuts at startup
182
202
 
@@ -198,7 +218,7 @@
198
218
  * Trying to remove a role scoped to a resource whereas the user has a global role won't remove it
199
219
 
200
220
  = v0.3 (June 06, 2011)
201
- * multiple roles check:
221
+ * multiple roles check:
202
222
  * <tt>has_all_roles?</tt> returns true if the user has ALL the roles in arguments
203
223
  * <tt>has_any_role?</tt> returns true if the user has ANY the roles in arguments
204
224
 
data/CONTRIBUTORS CHANGED
@@ -6,3 +6,12 @@ Mauro George (@MauroGeorge)
6
6
  Cheri Allen(@cherimarie)
7
7
  Gaurab Paul (@lorefnon)
8
8
  Dmitry Krakosevich (@DmitryKK)
9
+ Michael Watts (@mikwat)
10
+ Derek Ethier (@ethier)
11
+ Michael (@mibamur)
12
+ Undo1 (@Undo1)
13
+ Hitabis Engineering (@Hitabis)
14
+ Sergey Alekseev (@sergey-alekseev)
15
+ Sankalp Kulshreshtha (@sankalpk)
16
+ Kirill Sevastyanenko (@kirillseva)
17
+ Denis Shevchenko (@SimplySorc)
data/Gemfile CHANGED
@@ -4,10 +4,11 @@ group :test do
4
4
  gem 'appraisal'
5
5
  gem 'coveralls', :require => false
6
6
  gem 'its'
7
+ gem 'pry', '< 0.13.0' # pry pins can be removed when we drop Ruby 2.3
7
8
  gem 'byebug'
8
- gem 'pry-byebug'
9
+ gem 'pry-byebug', '< 3.8.0'
9
10
  gem 'test-unit' # Implicitly loaded by ammeter
10
- gem 'database_cleaner'
11
+ gem 'database_cleaner', '~> 1.6.2'
11
12
  gem 'codeclimate-test-reporter', :require => nil
12
13
  end
13
14
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 Florent Monbillard
1
+ Copyright (c) 2017 Florent Monbillard
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,28 +1,28 @@
1
- # rolify [![Gem Version](https://badge.fury.io/rb/rolify.svg)](http://badge.fury.io/rb/rolify) [![build status](https://secure.travis-ci.org/RolifyCommunity/rolify.png)](http://travis-ci.org/RolifyCommunity/rolify) [![Dependency Status](https://gemnasium.com/RolifyCommunity/rolify.svg)](https://gemnasium.com/RolifyCommunity/rolify) [![Code Climate](https://codeclimate.com/github/RolifyCommunity/rolify.png)](https://codeclimate.com/github/RolifyCommunity/rolify) [![Coverage Status](https://coveralls.io/repos/RolifyCommunity/rolify/badge.svg?branch=master&service=github)](https://coveralls.io/github/RolifyCommunity/rolify?branch=master)
1
+ # rolify [![Gem Version](https://badge.fury.io/rb/rolify.svg)](http://badge.fury.io/rb/rolify) [![build status](https://travis-ci.org/RolifyCommunity/rolify.svg)](http://travis-ci.org/RolifyCommunity/rolify) [![Code Climate](https://codeclimate.com/github/RolifyCommunity/rolify.svg)](https://codeclimate.com/github/RolifyCommunity/rolify) [![Coverage Status](https://coveralls.io/repos/RolifyCommunity/rolify/badge.svg?branch=master&service=github)](https://coveralls.io/github/RolifyCommunity/rolify?branch=master)
2
2
 
3
3
  Very simple Roles library without any authorization enforcement supporting scope on resource object.
4
4
 
5
5
  Let's see an example:
6
6
 
7
7
  ```ruby
8
- user.has_role?(:moderator, Forum.first)
8
+ user.has_role?(:moderator, @forum)
9
9
  => false # if user is moderator of another Forum
10
10
  ```
11
11
 
12
- This library can be easily integrated with any authentication gem ([devise](https://github.com/plataformatec/devise), [Authlogic](https://github.com/binarylogic/authlogic), [Clearance](https://github.com/thoughtbot/clearance)) and authorization gem<span style="color: red"><strong>*</strong></span> ([CanCanCan](https://github.com/CanCanCommunity/cancancan), [authority](https://github.com/nathanl/authority))
12
+ This library can be easily integrated with any authentication gem ([devise](https://github.com/plataformatec/devise), [Authlogic](https://github.com/binarylogic/authlogic), [Clearance](https://github.com/thoughtbot/clearance)) and authorization gem<span style="color: red"><strong>*</strong></span> ([CanCanCan](https://github.com/CanCanCommunity/cancancan), [authority](https://github.com/nathanl/authority), [Pundit](https://github.com/elabs/pundit))
13
13
 
14
14
  <span style="color: red"><strong>*</strong></span>: authorization gem that doesn't provide a role class
15
15
 
16
16
  ## Requirements
17
17
 
18
- * Rails >= 3.2
19
- * ActiveRecord >= 3.2 <b>or</b> Mongoid >= 3.1
20
- * supports ruby 2.0/1.9.3, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
18
+ * Rails >= 4.2
19
+ * ActiveRecord >= 4.2 <b>or</b> Mongoid >= 4.0
20
+ * supports ruby 2.2+, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
21
21
  * support of ruby 1.8 has been dropped due to Mongoid >=3.0 that only supports 1.9 new hash syntax
22
22
 
23
23
  ## Installation
24
24
 
25
- Add this to your Gemfile and run the +bundle+ command.
25
+ Add this to your Gemfile and run the `bundle` command.
26
26
 
27
27
  ```ruby
28
28
  gem "rolify"
@@ -32,7 +32,9 @@ gem "rolify"
32
32
 
33
33
  ### 1. Generate Role Model
34
34
 
35
- First, create your Role model and migration file using this generator:
35
+ First, use the generator to setup Rolify. Role and User class are the default names. However, you can specify any class name you want. For the User class name, you would probably use the one provided by your authentication solution.
36
+
37
+ If you want to use Mongoid instead of ActiveRecord, just add `--orm=mongoid` argument, and skip to step #3.
36
38
 
37
39
  ```
38
40
  rails g rolify Role User
@@ -44,10 +46,7 @@ rails g rolify Role User
44
46
  rails g rolify:role Role User
45
47
  ```
46
48
 
47
- Role and User classes are the default. You can specify any Role class name you want. This is a completely new file so any name will do the job.
48
- For the User class name, you would probably use the one provided by your authentication solution. rolify just adds some class methods in an existing User class.
49
-
50
- If you want to use Mongoid instead of ActiveRecord, just add `--orm=mongoid` argument, and skip to step #3
49
+ The generator will create your Role model, add a migration file, and update your User class with new class methods.
51
50
 
52
51
  ### 2. Run the migration (only required when using ActiveRecord)
53
52
 
@@ -80,6 +79,8 @@ The `rolify` method accepts the following callback options:
80
79
 
81
80
  Mongoid callbacks are also supported and works the same way.
82
81
 
82
+ The `rolify` method also accepts the `inverse_of` option if you need to disambiguate the relationship.
83
+
83
84
  ### 3.2 Configure your resource models
84
85
 
85
86
  In the resource models you want to apply roles on, just add ``resourcify`` method.
@@ -91,6 +92,18 @@ class Forum < ActiveRecord::Base
91
92
  end
92
93
  ```
93
94
 
95
+ ### 3.3 Assign default role
96
+
97
+ ```ruby
98
+ class User < ActiveRecord::Base
99
+ after_create :assign_default_role
100
+
101
+ def assign_default_role
102
+ self.add_role(:newuser) if self.roles.blank?
103
+ end
104
+ end
105
+ ```
106
+
94
107
  ### 4. Add a role to a user
95
108
 
96
109
  To define a global role:
@@ -114,6 +127,12 @@ user = User.find(3)
114
127
  user.add_role :moderator, Forum
115
128
  ```
116
129
 
130
+ Remove role:
131
+ ```ruby
132
+ user = User.find(3)
133
+ user.remove_role :moderator
134
+ ```
135
+
117
136
  That's it!
118
137
 
119
138
  ### 5. Role queries
@@ -162,6 +181,17 @@ user.has_role? :moderator, Forum.last
162
181
  => true
163
182
  ```
164
183
 
184
+ To check if a user has the exact role scoped to a resource class:
185
+
186
+ ```ruby
187
+ user = User.find(5)
188
+ user.add_role :moderator # sets a global role
189
+ user.has_role? :moderator, Forum.first
190
+ => true
191
+ user.has_strict_role? :moderator, Forum.last
192
+ => false
193
+ ```
194
+
165
195
  ### 6. Resource roles querying
166
196
 
167
197
  Starting from rolify 3.0, you can search roles on instance level or class level resources.
@@ -181,6 +211,8 @@ forum.applied_roles
181
211
  ```ruby
182
212
  Forum.with_role(:admin)
183
213
  # => [ list of Forum instances that have role "admin" bound to them ]
214
+ Forum.without_role(:admin)
215
+ # => [ list of Forum instances that do NOT have role "admin" bound to them ]
184
216
  Forum.with_role(:admin, current_user)
185
217
  # => [ list of Forum instances that have role "admin" bound to them and belong to current_user roles ]
186
218
  Forum.with_roles([:admin, :user], current_user)
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'coveralls/rake/task'
4
+ require 'appraisal'
4
5
 
5
6
  Bundler::GemHelper.install_tasks
6
7
 
@@ -2,18 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", :platform => "ruby"
6
- gem "activerecord", ">= 4.2.5", :require => "active_record"
5
+ gem "sqlite3", "~> 1.3.6"
6
+ gem "activerecord", "~> 4.2.11", require: "active_record"
7
+ gem "bigdecimal", "1.4.2"
7
8
 
8
9
  group :test do
9
10
  gem "appraisal"
10
- gem "coveralls", :require => false
11
+ gem "coveralls", require: false
11
12
  gem "its"
13
+ gem "pry", "< 0.13.0"
12
14
  gem "byebug"
13
- gem "pry-byebug"
15
+ gem "pry-byebug", "< 3.8.0"
14
16
  gem "test-unit"
15
- gem "database_cleaner"
16
- gem "codeclimate-test-reporter", :require => nil
17
+ gem "database_cleaner", "~> 1.6.2"
18
+ gem "codeclimate-test-reporter", require: nil
17
19
  end
18
20
 
19
- gemspec :path => "../"
21
+ gemspec path: "../"
@@ -2,26 +2,27 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", :platform => "ruby"
6
- gem "activerecord", ">= 5.0.0.beta", :require => "active_record"
7
- gem "actionpack", ">= 5.0.0.beta2"
8
- gem "activemodel", ">= 5.0.0.beta2"
9
- gem "railties", ">= 5.0.0.beta2"
10
- gem "rspec-rails", :github => "rspec/rspec-rails"
11
- gem "rspec-core", :github => "rspec/rspec-core"
12
- gem "rspec-expectations", :github => "rspec/rspec-expectations"
13
- gem "rspec-mocks", :github => "rspec/rspec-mocks"
14
- gem "rspec-support", :github => "rspec/rspec-support"
5
+ gem "sqlite3", "~> 1.3.6"
6
+ gem "activerecord", "~> 5.2.4", require: "active_record"
7
+ gem "actionpack", "~> 5.2.4"
8
+ gem "activemodel", "~> 5.2.4"
9
+ gem "railties", "~> 5.2.4"
10
+ gem "rspec-rails", github: "rspec/rspec-rails"
11
+ gem "rspec-core", github: "rspec/rspec-core"
12
+ gem "rspec-expectations", github: "rspec/rspec-expectations"
13
+ gem "rspec-mocks", github: "rspec/rspec-mocks"
14
+ gem "rspec-support", github: "rspec/rspec-support"
15
15
 
16
16
  group :test do
17
17
  gem "appraisal"
18
- gem "coveralls", :require => false
18
+ gem "coveralls", require: false
19
19
  gem "its"
20
+ gem "pry", "< 0.13.0"
20
21
  gem "byebug"
21
- gem "pry-byebug"
22
+ gem "pry-byebug", "< 3.8.0"
22
23
  gem "test-unit"
23
- gem "database_cleaner"
24
- gem "codeclimate-test-reporter", :require => nil
24
+ gem "database_cleaner", "~> 1.6.2"
25
+ gem "codeclimate-test-reporter", require: nil
25
26
  end
26
27
 
27
- gemspec :path => "../"
28
+ gemspec path: "../"
@@ -0,0 +1,28 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.4", platform: "ruby"
6
+ gem "activerecord", ">= 6.0.0", require: "active_record"
7
+ gem "actionpack", ">= 6.0.0"
8
+ gem "activemodel", ">= 6.0.0"
9
+ gem "railties", ">= 6.0.0"
10
+ gem "rspec-rails", github: "rspec/rspec-rails"
11
+ gem "rspec-core", github: "rspec/rspec-core"
12
+ gem "rspec-expectations", github: "rspec/rspec-expectations"
13
+ gem "rspec-mocks", github: "rspec/rspec-mocks"
14
+ gem "rspec-support", github: "rspec/rspec-support"
15
+
16
+ group :test do
17
+ gem "appraisal"
18
+ gem "coveralls", require: false
19
+ gem "its"
20
+ gem "pry", "< 0.13.0"
21
+ gem "byebug"
22
+ gem "pry-byebug", "< 3.8.0"
23
+ gem "test-unit"
24
+ gem "database_cleaner", "~> 1.6.2"
25
+ gem "codeclimate-test-reporter", require: nil
26
+ end
27
+
28
+ gemspec path: "../"
@@ -3,17 +3,19 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mongoid", "~> 5"
6
- gem "bson_ext", :platform => "ruby"
6
+ gem "bson_ext", "1.5.1"
7
+ gem "bigdecimal", "1.4.2"
7
8
 
8
9
  group :test do
9
10
  gem "appraisal"
10
- gem "coveralls", :require => false
11
+ gem "coveralls", require: false
11
12
  gem "its"
13
+ gem "pry", "< 0.13.0"
12
14
  gem "byebug"
13
- gem "pry-byebug"
15
+ gem "pry-byebug", "< 3.8.0"
14
16
  gem "test-unit"
15
- gem "database_cleaner"
16
- gem "codeclimate-test-reporter", :require => nil
17
+ gem "database_cleaner", "~> 1.6.2"
18
+ gem "codeclimate-test-reporter", require: nil
17
19
  end
18
20
 
19
- gemspec :path => "../"
21
+ gemspec path: "../"
@@ -0,0 +1,20 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 6"
6
+ gem "bson_ext", "1.5.1"
7
+
8
+ group :test do
9
+ gem "appraisal"
10
+ gem "coveralls", require: false
11
+ gem "its"
12
+ gem "pry", "< 0.13.0"
13
+ gem "byebug"
14
+ gem "pry-byebug", "< 3.8.0"
15
+ gem "test-unit"
16
+ gem "database_cleaner", "~> 1.6.2"
17
+ gem "codeclimate-test-reporter", require: nil
18
+ end
19
+
20
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 7"
6
+ gem "bson_ext", "1.5.1"
7
+ gem "railties", "5.2.4.1"
8
+
9
+ group :test do
10
+ gem "appraisal"
11
+ gem "coveralls", require: false
12
+ gem "its"
13
+ gem "pry", "< 0.13.0"
14
+ gem "byebug"
15
+ gem "pry-byebug", "< 3.8.0"
16
+ gem "test-unit"
17
+ gem "database_cleaner", "~> 1.6.2"
18
+ gem "codeclimate-test-reporter", require: nil
19
+ end
20
+
21
+ gemspec path: "../"