rbac_core 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: af8fa23cb6799737ab411e0db0cad9c7348e41fb
4
- data.tar.gz: 88c458eeb4f692e09c1a5612a39d1eb3eb7f1f4c
3
+ metadata.gz: e20bafe41484d58cc983f772cbf6e8da5e2a5fc2
4
+ data.tar.gz: 46c6e5d9e333fc34b50509ab8af8ae307e5956a9
5
5
  SHA512:
6
- metadata.gz: 1f67fab048dc53c91bf9eb1454613973c48bb223557b1c3ef1cc10d367831e016e9f40139f8f7c1ff7149d56c61b73444c1bf94d9512ac2f3465c691597b041e
7
- data.tar.gz: a7832ff71c2760be51d7bb134404809097a7db24f72301ce250e70168a13fba81465b1563f46cf66711f94eac7f7fd445b3085513fac8a9f3334542fe42ac9ca
6
+ metadata.gz: 14ea6df4a18e99d68f7d1dbfbf1241ca8791e34e426d1f59c5b857cce9d09acaf8cf1435b0405aebb5956a0522fcde04a862707cc2561320fc7004090cef923f
7
+ data.tar.gz: edf91774d3b6e340a7d854fb5806ed73f3fc49789797a0b52c101d62fa04f94d1260745bf614bce40400cdc8856a7936328c6df9019f155f3d12cbb139a1094e
@@ -0,0 +1,32 @@
1
+ module RbacCore
2
+ class ComputedPermissions
3
+ delegate :each, :map, :to_a, :to_ary, to: :@permissions
4
+
5
+ def initialize(permissions = [])
6
+ @permissions = [].concat permissions.to_a
7
+ regroup!
8
+ end
9
+
10
+ def concat(permissions)
11
+ @permissions.concat permissions
12
+ regroup!
13
+
14
+ self
15
+ end
16
+
17
+ def call(context, *args)
18
+ @permissions.each do |permission|
19
+ permission.call(context, *args)
20
+ end
21
+
22
+ self
23
+ end
24
+
25
+ private
26
+
27
+ def regroup!
28
+ @permissions.uniq!
29
+ @permissions.sort_by!(&:priority)
30
+ end
31
+ end
32
+ end
@@ -7,10 +7,10 @@ module RbacCore
7
7
  def permitted_permissions(include_nested: true)
8
8
  permissions = self.class.registered_permissions.slice(*permitted_permission_names).values
9
9
  if include_nested && nested_attributes.any?
10
- permissions + nested_attributes.values.map(&:permitted_permissions).flatten!
11
- else
12
- permissions
13
- end.sort_by(&:priority)
10
+ permissions.concat nested_attributes.values.map(&:permitted_permissions).flatten!
11
+ end
12
+
13
+ ComputedPermissions.new(permissions)
14
14
  end
15
15
 
16
16
  class << self
@@ -1,3 +1,3 @@
1
1
  module RbacCore
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
data/lib/rbac_core.rb CHANGED
@@ -4,6 +4,7 @@ require "options_model"
4
4
  require "rbac_core/permission"
5
5
  require "rbac_core/mapper"
6
6
  require "rbac_core/permission_set"
7
+ require "rbac_core/computed_permissions"
7
8
 
8
9
  require "rbac_core/concerns/models/role"
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbac_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,7 @@ files:
52
52
  - app/models/rbac_core/role.rb
53
53
  - db/migrate/20170705174003_create_rbac_core_roles.rb
54
54
  - lib/rbac_core.rb
55
+ - lib/rbac_core/computed_permissions.rb
55
56
  - lib/rbac_core/concerns/models/role.rb
56
57
  - lib/rbac_core/engine.rb
57
58
  - lib/rbac_core/mapper.rb