role_core 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/lib/generators/role_core/config/config_generator.rb +1 -1
- data/lib/generators/role_core/model/model_generator.rb +1 -1
- data/lib/role_core.rb +2 -6
- data/lib/role_core/computed_permissions.rb +4 -4
- data/lib/role_core/concerns/models/role.rb +1 -1
- data/lib/role_core/mapper.rb +3 -3
- data/lib/role_core/permission.rb +4 -8
- data/lib/role_core/permission_set.rb +11 -12
- data/lib/role_core/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37317c08fd473381f65f6d583ad90c3cc36ee2f79a27461d037d25c4a618a89d
|
4
|
+
data.tar.gz: 216d88ad8ae195f935b3096c156d4fe9490fb9c2491982fc36b7791af341ea26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec5646dfdc2648120ebb8b5fe8f300b97a3edf3e4ba613a38becf5a7b311ce77778afcdc55c1346f2271581835ba8046a785fec3cd90798570c6d9f7fc5082e8
|
7
|
+
data.tar.gz: b9dc82258bd777cc26996941e91c97b3750d81bd1e0040acf229f7a933d1385a2f68d3694fdc0ddcd4f4dde893e2435986ee3b209de59d725fb1afdc4ff12674
|
data/Rakefile
CHANGED
@@ -16,12 +16,12 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
16
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
17
17
|
end
|
18
18
|
|
19
|
-
APP_RAKEFILE = File.expand_path("
|
19
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
20
20
|
load "rails/tasks/engine.rake"
|
21
21
|
|
22
22
|
load "rails/tasks/statistics.rake"
|
23
23
|
|
24
|
-
require "bundler/gem_tasks"
|
24
|
+
# require "bundler/gem_tasks"
|
25
25
|
|
26
26
|
require "rake/testtask"
|
27
27
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RoleCore
|
4
4
|
module Generators
|
5
5
|
class ConfigGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path("
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
7
|
|
8
8
|
def generate_config
|
9
9
|
copy_file "role_core.rb", "config/initializers/role_core.rb"
|
data/lib/role_core.rb
CHANGED
@@ -17,9 +17,7 @@ module RoleCore
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def permission_set_class=(klass)
|
20
|
-
unless klass && klass < PermissionSet
|
21
|
-
raise ArgumentError, "#{klass} should be sub-class of #{PermissionSet}."
|
22
|
-
end
|
20
|
+
raise ArgumentError, "#{klass} should be sub-class of #{PermissionSet}." unless klass && klass < PermissionSet
|
23
21
|
|
24
22
|
@permission_set_class = klass.derive "Global"
|
25
23
|
end
|
@@ -29,9 +27,7 @@ module RoleCore
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def permission_class=(klass)
|
32
|
-
unless klass && klass < Permission
|
33
|
-
raise ArgumentError, "#{klass} should be sub-class of #{Permission}."
|
34
|
-
end
|
30
|
+
raise ArgumentError, "#{klass} should be sub-class of #{Permission}." unless klass && klass < Permission
|
35
31
|
|
36
32
|
@permission_class = klass
|
37
33
|
end
|
data/lib/role_core/mapper.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RoleCore
|
4
4
|
class Mapper
|
5
|
-
def initialize(set,
|
5
|
+
def initialize(set, constraints = {}) #:nodoc:
|
6
6
|
@constraints = constraints
|
7
7
|
@constraints[:_namespace] ||= []
|
8
8
|
@set = set
|
@@ -13,7 +13,7 @@ module RoleCore
|
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
16
|
-
def group(name,
|
16
|
+
def group(name, constraints = {}, &block)
|
17
17
|
raise ArgumentError, "`name` can't be blank" if name.blank?
|
18
18
|
raise ArgumentError, "must provide a block" unless block_given?
|
19
19
|
|
@@ -21,7 +21,7 @@ module RoleCore
|
|
21
21
|
constraints[:_namespace] << name
|
22
22
|
|
23
23
|
sub_permission_set_class =
|
24
|
-
if @set.nested_classes.
|
24
|
+
if @set.nested_classes.key?(name)
|
25
25
|
@set.nested_classes[name]
|
26
26
|
else
|
27
27
|
klass_name = constraints[:_namespace].map { |n| n.to_s.classify }.join("::")
|
data/lib/role_core/permission.rb
CHANGED
@@ -4,25 +4,21 @@ module RoleCore
|
|
4
4
|
class Permission
|
5
5
|
attr_reader :name, :namespace, :priority, :callable
|
6
6
|
|
7
|
-
def initialize(name, _namespace: [], _priority: 0, _callable: false, **
|
7
|
+
def initialize(name, _namespace: [], _priority: 0, _callable: false, **_options, &_block)
|
8
8
|
@name = name
|
9
9
|
@namespace = _namespace
|
10
10
|
@priority = _priority
|
11
11
|
@callable = _callable
|
12
12
|
end
|
13
13
|
|
14
|
-
def call(
|
14
|
+
def call(_context, *)
|
15
15
|
raise NotImplementedError
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
instance_values.hash
|
20
|
-
end
|
18
|
+
delegate :hash, to: :instance_values
|
21
19
|
|
22
20
|
def ==(other)
|
23
|
-
unless other.is_a?(RoleCore::Permission)
|
24
|
-
return false
|
25
|
-
end
|
21
|
+
return false unless other.is_a?(RoleCore::Permission)
|
26
22
|
|
27
23
|
instance_values == other.instance_values
|
28
24
|
end
|
@@ -8,9 +8,7 @@ module RoleCore
|
|
8
8
|
|
9
9
|
def computed_permissions(include_nesting: true)
|
10
10
|
permissions = self.class.registered_permissions.slice(*permitted_permission_names).values
|
11
|
-
if include_nesting && nested_attributes.any?
|
12
|
-
permissions.concat nested_attributes.values.map(&:computed_permissions).flatten!
|
13
|
-
end
|
11
|
+
permissions.concat nested_attributes.values.map(&:computed_permissions).flatten! if include_nesting && nested_attributes.any?
|
14
12
|
|
15
13
|
ComputedPermissions.new(permissions)
|
16
14
|
end
|
@@ -29,17 +27,13 @@ module RoleCore
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def permission_class=(klass)
|
32
|
-
unless klass && klass < Permission
|
33
|
-
raise ArgumentError, "#{klass} should be sub-class of #{Permission}."
|
34
|
-
end
|
30
|
+
raise ArgumentError, "#{klass} should be sub-class of #{Permission}." unless klass && klass < Permission
|
35
31
|
|
36
32
|
@permission_class = klass
|
37
33
|
end
|
38
34
|
|
39
|
-
def draw(
|
40
|
-
unless block_given?
|
41
|
-
raise ArgumentError, "must provide a block"
|
42
|
-
end
|
35
|
+
def draw(constraints = {}, &block)
|
36
|
+
raise ArgumentError, "must provide a block" unless block_given?
|
43
37
|
|
44
38
|
Mapper.new(self, constraints).instance_exec(&block)
|
45
39
|
|
@@ -50,11 +44,16 @@ module RoleCore
|
|
50
44
|
@registered_permissions ||= ActiveSupport::HashWithIndifferentAccess.new
|
51
45
|
end
|
52
46
|
|
53
|
-
def register_permission(name, default = false,
|
47
|
+
def register_permission(name, default = false, options = {}, &block)
|
54
48
|
raise ArgumentError, "`name` can't be blank" if name.blank?
|
55
49
|
|
56
50
|
attribute name, :boolean, default: default
|
57
|
-
registered_permissions[name] = permission_class.new name, options, &block
|
51
|
+
registered_permissions[name] = permission_class.new name, **options, &block
|
52
|
+
end
|
53
|
+
|
54
|
+
PERMITTED_ATTRIBUTE_CLASSES = [Symbol].freeze
|
55
|
+
def permitted_attribute_classes
|
56
|
+
PERMITTED_ATTRIBUTE_CLASSES
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
data/lib/role_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: role_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: options_model
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.15
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '1.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.0.15
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '1.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: rails
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: '5'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '7'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: '5'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '7'
|
53
53
|
description: RoleCore is a Rails engine which could provide essential industry of
|
54
54
|
Role-based access control.
|
55
55
|
email:
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.1.2
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: RoleCore is a Rails engine which could provide essential industry of Role-based
|