role_core 0.0.19 → 0.0.20

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: ffb852efc19e3620df7df31480f45d5d3e7fa9f09e4b9992f4e07ada92b5f74c
4
- data.tar.gz: f376183e99afc3ce34c0ed9a15c00b11e6d32d1a5c547a53834d6822802503ac
3
+ metadata.gz: 9edb95eb240054cb26913657fe3c3b6b1d723a02bf34bc1503435598e9299d99
4
+ data.tar.gz: 02666f872e3cdee62288e3e567ac157b30a88240f8e620c4e4777b2332da6b57
5
5
  SHA512:
6
- metadata.gz: 2d89c5b17180ef13389ed263ca091eeae551bc4f43d754e068649cc4ca814899c20191c56914e1409c2e0c5dd617ae13bf63ef7f8ffd4a6f6f80b3f8c8b92622
7
- data.tar.gz: e39cd77f4299a3df6766c1869a51b353336b57e06a2bb7675a5ade53211755f8c203dceaa6513465fa59414b708691a0083f443f41c99d69283ad71dfb60f785
6
+ metadata.gz: e87f6dc580136e18fc8fc95e527cd0cd3cc53d707e29531131253f405f5c62a789f86b396708011307a4e3bb3f7346a426b6a3beb78383461c105c6213fed6af
7
+ data.tar.gz: c1b1037ba4e4e192a0a46ea149157f141166ceed57ea42062f18ca0b448775ec0f71f6dcfb6dc69cac91d2ae46e641e3d6851d4aab96882c15905c9db894ab11
data/README.md CHANGED
@@ -285,6 +285,33 @@ user.can? { |permissions| permissions.project.read? }
285
285
 
286
286
  _Keep in mind: fetching `roles` will made a SQL query, you may need eager loading to avoid N+1 problem in some cases._
287
287
 
288
+ ### Integrate with Pundit
289
+
290
+ Just call permissions' method (see `checking permission` above) in Pundit's policy.
291
+
292
+ e.g:
293
+
294
+ ```ruby
295
+ class PostPolicy
296
+ attr_reader :user, :post
297
+
298
+ def initialize(user, post)
299
+ @user = user
300
+ @post = post
301
+ end
302
+
303
+ def update?
304
+ user.permissions.post.update?
305
+ end
306
+
307
+ def update_my_own?
308
+ return true if user.permissions.post.update?
309
+ return unless user.permissions.post.update_my_own?
310
+ post.author == user
311
+ end
312
+ end
313
+ ```
314
+
288
315
  ### Integrate with CanCanCan
289
316
 
290
317
  Open `config/initializers/role_core.rb`, uncomment CanCanCan integration codes and follows samples to define permissions for CanCanCan
@@ -8,7 +8,7 @@ module RoleCore
8
8
  super
9
9
  return unless _callable
10
10
 
11
- @model = options[:model] || options.fetch(:model_name).constantize
11
+ @model_name = options[:model_name]
12
12
  @action = options[:action] || name
13
13
  @options = options.except(:model, :model_name, :action)
14
14
  @block = block
@@ -17,10 +17,11 @@ module RoleCore
17
17
  def call(context, *args)
18
18
  return unless callable
19
19
 
20
+ model = @model_name.constantize
20
21
  if block_attached?
21
- context.can @action, @model, &@block.curry[*args]
22
+ context.can @action, model, &@block.curry[*args]
22
23
  else
23
- context.can @action, @model, @options
24
+ context.can @action, model, @options
24
25
  end
25
26
  end
26
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoleCore
4
- VERSION = "0.0.19"
4
+ VERSION = "0.0.20"
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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.7.6
98
+ rubygems_version: 2.7.7
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: RoleCore is a Rails engine which could provide essential industry of Role-based