role_core 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9edb95eb240054cb26913657fe3c3b6b1d723a02bf34bc1503435598e9299d99
4
- data.tar.gz: 02666f872e3cdee62288e3e567ac157b30a88240f8e620c4e4777b2332da6b57
3
+ metadata.gz: b54a7260db7b31f966bbedca0ccc5ca2931fe8c8c573c5b22dc4cd29046b9a04
4
+ data.tar.gz: 1e040dec8f41bb8cfa04ade4f1aa2ccf523fa34ac19c2eb804e6a8d3f08a4e95
5
5
  SHA512:
6
- metadata.gz: e87f6dc580136e18fc8fc95e527cd0cd3cc53d707e29531131253f405f5c62a789f86b396708011307a4e3bb3f7346a426b6a3beb78383461c105c6213fed6af
7
- data.tar.gz: c1b1037ba4e4e192a0a46ea149157f141166ceed57ea42062f18ca0b448775ec0f71f6dcfb6dc69cac91d2ae46e641e3d6851d4aab96882c15905c9db894ab11
6
+ metadata.gz: 8cab8dae514a9c0b5a16a061a14aee10575d0540270f42235fac3db27f4b5699118458791686556c043ce14bb1770430d1101f6dcb98570a263a5fe51c7cef8b
7
+ data.tar.gz: 6e2c93955b60e7bd0efb731d218d2ede540c67b77cc90f7cb4e0eaa814f66554692b1d1023e9fabed4d232d9d76a5de48aad5e99d88226a2d22b0ecce4d461b9
data/README.md CHANGED
@@ -68,6 +68,8 @@ and can be used with OO-style, for example: `role.permissions.project.create?`
68
68
 
69
69
  There also support permission groups, and groups support nesting.
70
70
 
71
+ **You don't need to any migration when you changing definitions.**
72
+
71
73
  I18n is supported too.
72
74
 
73
75
  In fact, the essence of permissions is Hash, keys are permissions, and values are booleans. so computing of permissions with many roles, can be understood as computing of Hashes.
@@ -345,6 +347,57 @@ You can check dummy app for better understanding.
345
347
  See [RolesController in dummy app](https://github.com/rails-engine/role_core/blob/master/test/dummy/app/controllers/roles_controller.rb)
346
348
  and relates [view](https://github.com/rails-engine/role_core/blob/master/test/dummy/app/views/roles/_form.html.erb) for details.
347
349
 
350
+ ## Hacking
351
+
352
+ RoleCore is a Rails engine, and following [the official best practice](http://guides.rubyonrails.org/engines.html#overriding-models-and-controllers), so you can extend RoleCore by the article suggests.
353
+
354
+ ### Integrate to existing role model
355
+
356
+ For some reason, you want to use RoleCore's ability and keeping use your own role model, e.g: integrate with [rolify](https://github.com/RolifyCommunity/rolify).
357
+
358
+ You can archive this goal by:
359
+
360
+ - Modify the migration file which RoleCore generated, changing the role table name
361
+ - Add `include RoleCore::Concerns::Models::Role` to your role model
362
+
363
+ *Note: If you want another column name or there's no name in your role model, you need to lookup `RoleCore::Concerns::Models::Role` source code, copy and modify to fit your needs*
364
+
365
+ ### Dynamic permissions
366
+
367
+ By design, RoleCore is for static permissions, but dynamic permissions is easy to support.
368
+
369
+ The key is `RoleCore::PermissionSet#derive`, that will generate a new anonymous sub-class of `PermissionSet`.
370
+
371
+ There's a example:
372
+
373
+ - Design a model to persisting dynamic permissions, e.g `DynamicPermission(id: bigint, name: string, default: bool)`
374
+ - Add `dynamic_permissions` column (`text` type) to Role model to persisting dynamic permissions' configuration, and in your model `serialize :dynamic_permissions, Hash`
375
+ - Generate dynamic permissions set in runtime
376
+ ```ruby
377
+ # Create a new permission set to containerize dynamic permissions
378
+ # `"Dynamic"` can be named to other but must be a valid Ruby class name,
379
+ # that's a hacking for `ActiveModel::Naming`,
380
+ # and can be used as I18n key, in this case, the key is `role_core/models/dynamic`.
381
+ dynamic_permission_set_class = PermissionSet.derive "Dynamic"
382
+
383
+ # Fetching dynamic permissions
384
+ dynamic_permissions = DynamicPermission.all
385
+
386
+ # Mapping dynamic permissions to permission set
387
+ dynamic_permission_set_class.draw do
388
+ dynamic_permissions.each do |p|
389
+ permission p.name, default: p.default
390
+ end
391
+ end
392
+ ```
393
+ - Create a instance of this dynamic permission set
394
+ ```ruby
395
+ dynamic_permissions = dynamic_permission_set_class.new(role.dynamic_permissions)
396
+ ```
397
+ - You can use the `dynamic_permissions` now
398
+
399
+ Rails' `serialize` is static so you must do serialize and deserialize manually, you can wrap these logic into model.
400
+
348
401
  ## Contributing
349
402
 
350
403
  Bug report or pull request are welcome.
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # YOU NEED TO RESTART APP AFTER CHANGING THIS FILE
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # For I18n, see `config/locales/role_core.en.yml` for details which followed the rule of ActiveRecord's I18n,
6
+ # See <http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models>.
4
7
 
5
8
  # Uncomment below if you want to integrate with CanCanCan
6
9
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoleCore
4
- VERSION = "0.0.20"
4
+ VERSION = "0.0.21"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-13 00:00:00.000000000 Z
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: options_model
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.10
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: '0'
42
+ version: '1.0'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.10
50
+ - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: '0'
52
+ version: '1.0'
47
53
  description: RoleCore is a Rails engine which could provide essential industry of
48
54
  Role-based access control.
49
55
  email: