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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 588687072ceb69fb165d2c7f86d8bb0dae0c814d33049221466dc4c0adcacfb0
4
- data.tar.gz: 2c0cf9515890e0389246d4fb4f570b3f39aae95781ad616d0c6306917df25a55
3
+ metadata.gz: 37317c08fd473381f65f6d583ad90c3cc36ee2f79a27461d037d25c4a618a89d
4
+ data.tar.gz: 216d88ad8ae195f935b3096c156d4fe9490fb9c2491982fc36b7791af341ea26
5
5
  SHA512:
6
- metadata.gz: 1c1419d298d3664ea384f88d68db83fd4209bda7827e826ede86c5720d170b3d83874e8df9650917a5ca93dac0ff79c4bda3a5f1e7d67c1cc292396ef46d6a14
7
- data.tar.gz: 83d4392b01a8766946f8c1e8fd1695d481f351d24628feab71724982c0c7d883b5b691ea961e29e73809ff73974fbcaab4c1158772a392ebd8d5ae56aecf3f52
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("../test/dummy/Rakefile", __FILE__)
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("../templates", __FILE__)
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"
@@ -3,7 +3,7 @@
3
3
  module RoleCore
4
4
  module Generators
5
5
  class ModelGenerator < Rails::Generators::Base
6
- source_root File.expand_path("../templates", __FILE__)
6
+ source_root File.expand_path("templates", __dir__)
7
7
 
8
8
  def generate_model
9
9
  copy_file "role.rb", "app/models/role.rb"
@@ -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
@@ -26,9 +26,9 @@ module RoleCore
26
26
 
27
27
  private
28
28
 
29
- def regroup!
30
- @permissions.uniq!
31
- @permissions.sort_by!(&:priority)
32
- end
29
+ def regroup!
30
+ @permissions.uniq!
31
+ @permissions.sort_by!(&:priority)
32
+ end
33
33
  end
34
34
  end
@@ -15,7 +15,7 @@ module RoleCore::Concerns
15
15
  end
16
16
 
17
17
  def permissions_attributes=(value)
18
- permissions.update_attributes value
18
+ self[:permissions].replace value
19
19
  end
20
20
  end
21
21
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RoleCore
4
4
  class Mapper
5
- def initialize(set, **constraints) #:nodoc:
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, **constraints, &block)
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.has_key?(name)
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("::")
@@ -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, **options, &block)
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(context, *)
14
+ def call(_context, *)
15
15
  raise NotImplementedError
16
16
  end
17
17
 
18
- def hash
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(**constraints, &block)
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, **options, &block)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoleCore
4
- VERSION = "0.0.25"
4
+ VERSION = "0.0.26"
5
5
  end
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.25
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-04-14 00:00:00.000000000 Z
11
+ date: 2019-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: options_model
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5'
19
+ version: 0.0.15
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
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: '5'
29
+ version: 0.0.15
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '1.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: options_model
34
+ name: rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.0.12
39
+ version: '5'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '1.0'
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: 0.0.12
49
+ version: '5'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '1.0'
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.0.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