role_core 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 293e6cf06bd28270f0d19f2d20f57ea8387849067b324fcfea3fb627cb11c841
4
- data.tar.gz: d1e32d432228cc32598e0309474179d7eaea3fc9734be71fc5f3717dd27b5ebb
3
+ metadata.gz: 63f9af3dc716a40099563d28bc8f409c0ae479eef42ece8ddd24fa3a90ab48c9
4
+ data.tar.gz: 44e757638be123b0877bf868814f712f920b48e5b8f3bb950fc83c1e4f649a62
5
5
  SHA512:
6
- metadata.gz: 8c6d27326c402fe05183bd06840c84621093905efb98beafc9969c1d8847e9268f26e990ffaec62436ae9bc8316d10afe4080dac7eda9abe6e374de6edc1042e
7
- data.tar.gz: 74385a5cce46f0202ea498916fa7471added4ad6185b13f19d2dcd7eac1d2810c9d159a0f535bf691d80fe6c5ffdc0dfcd06d59260e582c48c824396c346a4aa
6
+ metadata.gz: 4151358dfb0e084f9e5c3be912ba6e605610fe80ef1bce0af72c01120df8c8f9061554dc427f00fbcc611bc5050a59c512828b7b0945d128b45eaad0bfdb954f
7
+ data.tar.gz: 5827598c230b815ef22ba4db1d08f21136495d96419430a5e86c92f48d9790244a8988e0712c80485c8346a01027df2066dfd60032b70e0735a0ecd3dbf3889d
@@ -1,8 +1,8 @@
1
1
  en:
2
2
  role_core:
3
3
  models: # Defined by `group` place here
4
- # project: Project
5
- # task: Task
4
+ # project: Projects
5
+ # project/task: Tasks # A nested group
6
6
  attributes:
7
7
  # global: # Top-level permissions
8
8
  # foo: Foo
@@ -11,10 +11,11 @@ en:
11
11
  # create: New project
12
12
  # destroy: Destroy project
13
13
  # update: Edit project
14
- # read: Read project
15
- # read_public: Read public project
16
- # task:
14
+ # read: Read projects
15
+ # read_public: Read public projects
16
+ # project/task:
17
17
  # create: New task
18
18
  # destroy: Destroy task
19
19
  # update: Edit task
20
20
  # update_my_own: Edit my own task
21
+ # destroy_my_own: Destroy my own task
@@ -42,11 +42,11 @@ RoleCore.permission_set_class.draw do
42
42
  # can :create, Project
43
43
  # can :destroy, Plan
44
44
  #
45
- # You can pass `priority` argument to `permission`
45
+ # You can pass `_priority` argument to `permission`
46
46
  #
47
47
  # group :project, model_name: "Project" do
48
48
  # permission :read_public,
49
- # permission :read, priority: 1
49
+ # permission :read, _priority: 1
50
50
  # end
51
51
  #
52
52
  # That will made 'read' prior than `read_public`.
@@ -4,7 +4,7 @@ module RoleCore
4
4
  class CanCanCanPermission < RoleCore::Permission
5
5
  attr_reader :action, :options
6
6
 
7
- def initialize(name, priority: 0, **options, &block)
7
+ def initialize(name, _namespace: [], _priority: 0, **options, &block)
8
8
  super
9
9
 
10
10
  @model = options[:model] || options.fetch(:model_name).constantize
@@ -4,6 +4,7 @@ module RoleCore
4
4
  class Mapper
5
5
  def initialize(set, **constraints) #:nodoc:
6
6
  @constraints = constraints
7
+ @constraints[:_namespace] ||= []
7
8
  @set = set
8
9
  end
9
10
 
@@ -16,11 +17,15 @@ module RoleCore
16
17
  raise ArgumentError, "`name` can't be blank" if name.blank?
17
18
  raise ArgumentError, "must provide a block" unless block_given?
18
19
 
20
+ constraints[:_namespace] ||= @constraints[:_namespace].dup
21
+ constraints[:_namespace] << name
22
+
19
23
  sub_permission_set_class =
20
24
  if @set.nested_classes.has_key?(name)
21
25
  @set.nested_classes[name]
22
26
  else
23
- klass = PermissionSet.derive "#{name.to_s.classify}"
27
+ klass_name = constraints[:_namespace].map { |n| n.to_s.classify }.join("::")
28
+ klass = PermissionSet.derive klass_name
24
29
  @set.embeds_one(name, anonymous_class: klass)
25
30
 
26
31
  klass
@@ -2,11 +2,12 @@
2
2
 
3
3
  module RoleCore
4
4
  class Permission
5
- attr_reader :name, :priority
5
+ attr_reader :name, :namespace, :priority
6
6
 
7
- def initialize(name, priority: 0, **options, &block)
7
+ def initialize(name, _namespace: [], _priority: 0, **options, &block)
8
8
  @name = name
9
- @priority = priority
9
+ @namespace = _namespace
10
+ @priority = _priority
10
11
  end
11
12
 
12
13
  def call(context, *)
@@ -20,6 +20,10 @@ module RoleCore
20
20
  :role_core
21
21
  end
22
22
 
23
+ def use_relative_model_naming?
24
+ true
25
+ end
26
+
23
27
  def permission_class
24
28
  @permission_class || RoleCore.permission_class
25
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoleCore
4
- VERSION = "0.0.15"
4
+ VERSION = "0.0.16"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl