cancancan-system 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +331 -0
- data/app/models/concerns/cancancan/system/ability.rb +149 -0
- data/lib/cancancan-system.rb +11 -0
- data/lib/cancancan-system/engine.rb +8 -0
- data/lib/cancancan-system/version.rb +7 -0
- data/lib/generators/cancancan_system_generator.rb +35 -0
- data/lib/generators/templates/README.md +1 -0
- data/lib/generators/templates/migration.rb.erb +5 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 94f86f5710ad3064cb2fbd31f4894fda9bc079b26701f7ed351c5a52ad59821f
|
4
|
+
data.tar.gz: e81ae0727b09aa9e0a137962c46927c0ca313bdc2480aa964c661fa11e09d882
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a35d4aac231b628f6b3223b46308719f5916d030f5b5f07d48a502db0ba4cc5c8f717d372b92059c7f556bccae684646ab21b11918608890f1f0b02389c28ecc
|
7
|
+
data.tar.gz: c88efd88664474247b41b0b2b91672f594140d55f5f3c0d7eed44ba8127d0d541ad926a82f5357aa1f04aafadeaaff4654cc0f351eea0c5be71235f7ec35e080
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jonas Hübotter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,331 @@
|
|
1
|
+
# CanCanCan System
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/cancancan-system.svg)](https://badge.fury.io/rb/cancancan-system) <img src="https://travis-ci.org/jonhue/cancancan-system.svg?branch=master" />
|
4
|
+
|
5
|
+
Conventions & helpers simplifying the use of CanCanCan in complex Rails applications. CanCanCan System simplifies authorizing collaborations, memberships and more across a complex structure of models.
|
6
|
+
|
7
|
+
To describe complex abilities CanCanCan System relies on two different constructs: ActiveRecord **objects**, and **relationships** of users to those objects.
|
8
|
+
|
9
|
+
CanCanCan System uses two attributes on *objects* to describe abilities:
|
10
|
+
|
11
|
+
* **ability:** Describes the default ability of users without a special relationship with an object.
|
12
|
+
* **visiblity:** Specifies whether an object is visible to other users than the creator.
|
13
|
+
|
14
|
+
CanCanCan System uses one attribute on *relationships* to describe abilities:
|
15
|
+
|
16
|
+
* **ability:** Describes the ability of a user with the related object.
|
17
|
+
|
18
|
+
`ability` can have any CanCanCan permission, `'admin'` (`:manage`), `'user'` (`:modify`) or `'guest'` (`:read`) as value while `visiblity` is limited to `public` and `private`.
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## Table of Contents
|
23
|
+
|
24
|
+
* [Installation](#installation)
|
25
|
+
* [Usage](#usage)
|
26
|
+
* [Defining abilities](#defining-abilities)
|
27
|
+
* [Public abilities](#public-abilities)
|
28
|
+
* [acts_as_belongable abilities](#acts_as_belongable-abilities)
|
29
|
+
* [Membership abilities](#membership-abilities)
|
30
|
+
* [Get abilities](#get-abilities)
|
31
|
+
* [To Do](#to-do)
|
32
|
+
* [Contributing](#contributing)
|
33
|
+
* [Contributors](#contributors)
|
34
|
+
* [Semantic versioning](#semantic-versioning)
|
35
|
+
* [License](#license)
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
## Installation
|
40
|
+
|
41
|
+
CanCanCan System works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'cancancan-system'
|
45
|
+
```
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
|
49
|
+
$ bundle
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
$ gem install cancancan-system
|
54
|
+
|
55
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
gem 'cancancan-system', github: 'jonhue/cancancan-system'
|
59
|
+
```
|
60
|
+
|
61
|
+
Now run the generator:
|
62
|
+
|
63
|
+
$ rails g cancancan_system
|
64
|
+
|
65
|
+
To wrap things up, migrate the changes to your database:
|
66
|
+
|
67
|
+
$ rails db:migrate
|
68
|
+
|
69
|
+
---
|
70
|
+
|
71
|
+
## Usage
|
72
|
+
|
73
|
+
To get started add CanCanCan System to your `Ability` class (`app/models/ability.rb`) and add the required `:modify` alias:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class Ability
|
77
|
+
|
78
|
+
include CanCan::Ability
|
79
|
+
include CanCanCan::System::Ability
|
80
|
+
|
81
|
+
def initialize user
|
82
|
+
modify [:create, :read, :update, :destroy]
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
**Note:** The aliases (`:create, :read, :update, :destroy`) can be custom.
|
89
|
+
|
90
|
+
### Defining Abilities
|
91
|
+
|
92
|
+
CanCanCan System makes an `abilities` method available which simplifies setting up common abilities:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
def initialize user
|
96
|
+
abilities Post, user
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
This is equivalent to:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
def initialize user
|
104
|
+
public_abilities Post
|
105
|
+
can :manage, Post, user_id: user.id if user
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
You can also use the `abilities` method with custom column names and polymorphic associations. This comes in handy when using the [NotificationsRails gem](https://github.com/jonhue/notifications-rails):
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
def initialize user
|
113
|
+
abilities Notification, user, column: 'target', polymorphic: true, public_abilities: false
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
This is equivalent to:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
def initialize user
|
121
|
+
can :manage, Notification, target_id: user.id, target_type: user.class.name if user
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
Learn more about the `public_abilities` method [here](#public-abilities).
|
126
|
+
|
127
|
+
#### Public abilities
|
128
|
+
|
129
|
+
The `public_abilities` method defines the object-abilities without a `user` being present:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
def initialize user
|
133
|
+
public_abilities Post
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
This is equivalent to:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
def initialize user
|
141
|
+
can :manage, Post, ability: 'admin', visibility: 'public'
|
142
|
+
can :modify, Post, ability: 'user', visibility: 'public'
|
143
|
+
can :read, Post, ability: 'guest', visibility: 'public'
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
#### acts_as_belongable abilities
|
148
|
+
|
149
|
+
CanCanCan System integrates with the [acts_as_belongable gem](https://github.com/jonhue/acts_as_belongable) to make defining abilities for relationships dead simple.
|
150
|
+
|
151
|
+
Let's say our users can be a member of multiple organizations:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
class User < ApplicationRecord
|
155
|
+
acts_as_belongable
|
156
|
+
belongable :member_of_organizations, 'Organization', scope: :membership
|
157
|
+
has_many :organizations
|
158
|
+
end
|
159
|
+
|
160
|
+
class Organization < ApplicationRecord
|
161
|
+
acts_as_belonger
|
162
|
+
belonger :members, 'User', scope: :membership
|
163
|
+
belongs_to :user
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
We would then just do:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
def initialize user
|
171
|
+
abilities Organization, user do
|
172
|
+
belonger_abilities Organization, user, scope: :membership
|
173
|
+
end
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
**Note:** This can be done in the same way with `belongable_abilities` for `belongable` relationships.
|
178
|
+
|
179
|
+
Now we are able to add members to our organizations and set their abilities:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
Organization.first.add_belongable User.first, scope: :membership, ability: 'admin'
|
183
|
+
```
|
184
|
+
|
185
|
+
**Note:** The `scope` option is optional. If omitted, the defined abilities will apply to all belongings regardless of their scope.
|
186
|
+
|
187
|
+
#### Membership abilities
|
188
|
+
|
189
|
+
Now, let us assume that we have another model: `Post`.
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
class User < ApplicationRecord
|
193
|
+
acts_as_belongable
|
194
|
+
belongable :member_of_organizations, 'Organization', scope: :membership
|
195
|
+
has_many :posts
|
196
|
+
has_many :organizations
|
197
|
+
end
|
198
|
+
|
199
|
+
class Organization < ApplicationRecord
|
200
|
+
acts_as_belonger
|
201
|
+
belonger :members, 'User', scope: :membership
|
202
|
+
has_many :posts
|
203
|
+
belongs_to :user
|
204
|
+
end
|
205
|
+
|
206
|
+
class Post < ApplicationRecord
|
207
|
+
belongs_to :user
|
208
|
+
belongs_to :organization
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
You want the posts of an organization to be accessible for its members. It doesn't get any simpler than this:
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
def initialize user
|
216
|
+
abilities Post, user do
|
217
|
+
organization_abilities Post, user, scope: :membership
|
218
|
+
end
|
219
|
+
end
|
220
|
+
```
|
221
|
+
|
222
|
+
**Note:** The `scope` option is optional. If omitted, the defined abilities will apply to all belongings regardless of their scope.
|
223
|
+
|
224
|
+
You are also able to perform some customization:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
class Post < ApplicationRecord
|
228
|
+
belongs_to :user
|
229
|
+
belongs_to :object, polymorphic: true
|
230
|
+
end
|
231
|
+
```
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
def initialize user
|
235
|
+
abilities Post, user do
|
236
|
+
organization_abilities Post, user, scope: :membership, column: 'object', polymorphic: true
|
237
|
+
end
|
238
|
+
end
|
239
|
+
```
|
240
|
+
|
241
|
+
Another option is to use the [acts_as_belongable gem](https://github.com/jonhue/acts_as_belongable) to associate posts with organizations:
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
class Organization < ApplicationRecord
|
245
|
+
acts_as_belonger
|
246
|
+
belonger :members, 'User', scope: :membership
|
247
|
+
belonger :posts, 'Post'
|
248
|
+
has_many :posts
|
249
|
+
belongs_to :user
|
250
|
+
end
|
251
|
+
|
252
|
+
class Post < ApplicationRecord
|
253
|
+
acts_as_belongable
|
254
|
+
belongable :organizations, 'Organization'
|
255
|
+
belongs_to :user
|
256
|
+
end
|
257
|
+
```
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
def initialize user
|
261
|
+
abilities Post, user do
|
262
|
+
organization_abilities Post, user, scope: :membership, acts_as_belongable: true
|
263
|
+
end
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
**Note:** If your `acts_as_belongable` association in the `Post` model is not following the CanCanCan System naming convention, you can override it by passing the `column` option.
|
268
|
+
|
269
|
+
### Get abilities
|
270
|
+
|
271
|
+
You can use the `ability` method to get the ability of an ActiveRecord object:
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
Organization.first.ability
|
275
|
+
# => 'guest'
|
276
|
+
|
277
|
+
ability Organization.first
|
278
|
+
# => :read
|
279
|
+
```
|
280
|
+
|
281
|
+
It returns a symbol or `nil`.
|
282
|
+
|
283
|
+
---
|
284
|
+
|
285
|
+
## To Do
|
286
|
+
|
287
|
+
[Here](https://github.com/jonhue/cancancan-system/projects/1) is the full list of current projects.
|
288
|
+
|
289
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/cancancan-system/issues/new).
|
290
|
+
|
291
|
+
---
|
292
|
+
|
293
|
+
## Contributing
|
294
|
+
|
295
|
+
We hope that you will consider contributing to CanCanCan System. Please read this short overview for some information about how to get started:
|
296
|
+
|
297
|
+
[Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
|
298
|
+
|
299
|
+
### Contributors
|
300
|
+
|
301
|
+
Give the people some :heart: who are working on this project. See them all at:
|
302
|
+
|
303
|
+
https://github.com/jonhue/cancancan-system/graphs/contributors
|
304
|
+
|
305
|
+
### Semantic Versioning
|
306
|
+
|
307
|
+
CanCanCan System follows Semantic Versioning 2.0 as defined at http://semver.org.
|
308
|
+
|
309
|
+
## License
|
310
|
+
|
311
|
+
MIT License
|
312
|
+
|
313
|
+
Copyright (c) 2018 Jonas Hübotter
|
314
|
+
|
315
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
316
|
+
of this software and associated documentation files (the "Software"), to deal
|
317
|
+
in the Software without restriction, including without limitation the rights
|
318
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
319
|
+
copies of the Software, and to permit persons to whom the Software is
|
320
|
+
furnished to do so, subject to the following conditions:
|
321
|
+
|
322
|
+
The above copyright notice and this permission notice shall be included in all
|
323
|
+
copies or substantial portions of the Software.
|
324
|
+
|
325
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
326
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
327
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
328
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
329
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
330
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
331
|
+
SOFTWARE.
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module CanCanCan
|
2
|
+
module System
|
3
|
+
module Ability
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def method_missing m, *args
|
8
|
+
if m.to_s[/(.+)_abilities/]
|
9
|
+
membership_abilities $1, args
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to? m, include_private = false
|
16
|
+
super || m.to_s[/(.+)_abilities/]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def modify aliases
|
22
|
+
alias_action aliases, to: :modify
|
23
|
+
end
|
24
|
+
|
25
|
+
def abilities record_class, user, options = {}
|
26
|
+
defaults = {
|
27
|
+
column: 'user',
|
28
|
+
polymorphic: false,
|
29
|
+
public_abilities: true
|
30
|
+
}
|
31
|
+
options = defaults.merge options
|
32
|
+
|
33
|
+
public_abilities record_class if options[:public_abilities]
|
34
|
+
if user
|
35
|
+
if options[:polymorphic]
|
36
|
+
can :manage, record_class, "#{options[:column]}_id": user.id, "#{options[:column]}_type": user.class.name
|
37
|
+
else
|
38
|
+
can :manage, record_class, "#{options[:column]}_id": user.id
|
39
|
+
end
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def membership_abilities class_name, record_class, user, options = {}
|
45
|
+
defaults = {
|
46
|
+
scope: :membership,
|
47
|
+
column: nil,
|
48
|
+
polymorphic: false,
|
49
|
+
acts_as_belongable: false
|
50
|
+
}
|
51
|
+
options = defaults.merge options
|
52
|
+
|
53
|
+
user.belongable_belongings.where(scope: options[:scope].to_s).each do |belonging|
|
54
|
+
if belonging.belonger_type == class_name.camelize
|
55
|
+
ability = ability belonging
|
56
|
+
if options[:acts_as_belongable]
|
57
|
+
can ability, record_class, "#{column || class_name.pluralize}": { id: belonging.belonger_id }
|
58
|
+
else
|
59
|
+
if options[:polymorphic]
|
60
|
+
can ability, record_class, "#{column || class_name}_id": belonging.belonger_id, "#{column || class_name}_type": belonging.belonger_type
|
61
|
+
else
|
62
|
+
can ability, record_class, "#{column || class_name}_id": belonging.belonger_id
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
user.send("#{class_name.pluralize}").each do |object|
|
68
|
+
if options[:acts_as_belongable]
|
69
|
+
can :manage, record_class, "#{column || class_name.pluralize}": { id: object.id }
|
70
|
+
else
|
71
|
+
if options[:polymorphic]
|
72
|
+
can :manage, record_class, "#{column || class_name}_id": object.id, "#{column || class_name}_type": object.class.name
|
73
|
+
else
|
74
|
+
can :manage, record_class, "#{column || class_name}_id": object.id
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def belongable_abilities record_class, user, options = {}
|
81
|
+
defaults = {
|
82
|
+
scope: nil
|
83
|
+
}
|
84
|
+
options = defaults.merge options
|
85
|
+
|
86
|
+
if scope.nil?
|
87
|
+
user.belongable_belongings.each do |belonging|
|
88
|
+
belongable_belonging belonging
|
89
|
+
end
|
90
|
+
else
|
91
|
+
user.belongable_belongings.where(scope: scope.to_s).each do |belonging|
|
92
|
+
belongable_belonging belonging
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
def belongable_belonging belonging
|
97
|
+
if belonging.belonger_type == record_class.name
|
98
|
+
ability = ability belonging
|
99
|
+
can ability, record_class, id: belonging.belonger_id if ability
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def belonger_abilities record_class, user, options = {}
|
104
|
+
defaults = {
|
105
|
+
scope: nil
|
106
|
+
}
|
107
|
+
options = defaults.merge options
|
108
|
+
|
109
|
+
if scope.nil?
|
110
|
+
user.belonger_belongings.each do |belonging|
|
111
|
+
belonger_belonging belonging
|
112
|
+
end
|
113
|
+
else
|
114
|
+
user.belonger_belongings.where(scope: scope.to_s).each do |belonging|
|
115
|
+
belonger_belonging belonging
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
def belonger_belonging belonging
|
120
|
+
if belonging.belongable_type == record_class.name
|
121
|
+
ability = ability belonging
|
122
|
+
can ability, record_class, id: belonging.belongable_id if ability
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def public_abilities record_class
|
127
|
+
can :manage, record_class, ability: 'admin', visibility: 'public'
|
128
|
+
can :modify, record_class, ability: 'user', visibility: 'public'
|
129
|
+
can :read, record_class, ability: 'guest', visibility: 'public'
|
130
|
+
end
|
131
|
+
|
132
|
+
def ability object
|
133
|
+
case object.ability
|
134
|
+
when 'admin'
|
135
|
+
:manage
|
136
|
+
when 'user'
|
137
|
+
:modify
|
138
|
+
when 'guest'
|
139
|
+
:read
|
140
|
+
when nil
|
141
|
+
nil
|
142
|
+
else
|
143
|
+
object.ability.to_sym
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class CancancanSystemGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.join File.dirname(__FILE__), 'templates'
|
9
|
+
desc 'Install CanCanCan System'
|
10
|
+
|
11
|
+
def self.next_migration_number dirname
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
14
|
+
else
|
15
|
+
"%.3d" % ( current_migration_number(dirname) + 1 )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration_file
|
20
|
+
migration_template 'migration.rb.erb', 'db/migrate/cancancan_system_migration.rb', migration_version: migration_version
|
21
|
+
end
|
22
|
+
|
23
|
+
def show_readme
|
24
|
+
readme 'README.md'
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def migration_version
|
30
|
+
if Rails.version >= '5.0.0'
|
31
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Now run `rails db:migrate` to add CanCanCan System to your database.
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cancancan-system
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Hübotter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cancancan
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: acts_as_belongable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.52'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.52'
|
97
|
+
description: Conventions & helpers simplifying the use of CanCanCan in complex Rails
|
98
|
+
applications.
|
99
|
+
email: me@jonhue.me
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- LICENSE
|
106
|
+
- README.md
|
107
|
+
- app/models/concerns/cancancan/system/ability.rb
|
108
|
+
- lib/cancancan-system.rb
|
109
|
+
- lib/cancancan-system/engine.rb
|
110
|
+
- lib/cancancan-system/version.rb
|
111
|
+
- lib/generators/cancancan_system_generator.rb
|
112
|
+
- lib/generators/templates/README.md
|
113
|
+
- lib/generators/templates/migration.rb.erb
|
114
|
+
homepage: https://github.com/jonhue/cancancan-system
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '2.3'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.7.4
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Conventions & helpers simplifying the use of CanCanCan in complex Rails applications
|
138
|
+
test_files: []
|