i_am_i_can 4.3.0 → 4.3.1

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
  SHA1:
3
- metadata.gz: 7afc85dd06b6aefeec8da4d575782398aca2f5c0
4
- data.tar.gz: f23e1e9768cbfdac758e7df5a3be484ebbebf2e8
3
+ metadata.gz: 52f2148f7b7693972fbf12b9f573967491caf3ee
4
+ data.tar.gz: d1282f21e4d23e9ab713e58fea2b91a23790074a
5
5
  SHA512:
6
- metadata.gz: 6aa217add1124db25b3f79d5a3ff40ee43b18dcb28dfaad9fc9ebbd4d7eb3997be8bdb18f0ce88492817296b0aaae31963a935a4f54ea180d4c457730b773aca
7
- data.tar.gz: ef73fda2b4d9bdcbe779d5a748ddfafe09561943f4520620cf441ae852bc1fa9f2b7db7afd978d5cca845740b0271ed63bb76f27d3781feeba0dd2bd5aca14c6
6
+ metadata.gz: 32175d334cfa85c56d7ef787ee2f4d5a3d8995df40e26f6311581e9995d0d1844c02cd8c54c884101647ed79f7ff3b7d03ee87763e2ed573f97c631f4f01f9e5
7
+ data.tar.gz: eb09a250c1bb986a5ef19034d94e9cd53773a4bb5adc216436dd46f44c975b97a74facbce1fd22c70d59fe5e48bc4d8b7e04c709ed09dd20f3dae796c211ea64
data/README.md CHANGED
@@ -292,7 +292,7 @@ becomes_a *roles, which_can: [ ], obj: nil,
292
292
  he.becomes_a :admin # => 'Role Assignment Done' or error message
293
293
  he.stored_roles # => [<#UserRole id: 1>]
294
294
  # 2. example of giving role instances to `roles` params
295
- he.becomes_a *UserRole.all # => 'Role Assignment Done' or error message
295
+ he.becomes_a UserRole.all # => 'Role Assignment Done' or error message
296
296
  he.stored_roles # => [<#UserRole id: 1>, <#UserRole id: 2>]
297
297
  # 3. `expires` (subject assocates roles with a `expire_at` scope)
298
298
  he.is_a :visitor, expires_in: 1.hour # or `expires_at: 1.hour.after`
@@ -410,7 +410,7 @@ can *actions, resource: nil, obj: resource, # you can use `resource` or `obj`
410
410
  role.can :fly # => 'Permission Assignment Done' or error message
411
411
  role.permissions # => [<#UserPermission id: ..>]
412
412
  # you can also passing permission instances to `actions` params, like:
413
- role.can *UserPermission.all
413
+ role.can UserPermission.all
414
414
 
415
415
  # === Cancel Assignment ===
416
416
  # method signature
@@ -26,13 +26,13 @@ module IAmICan
26
26
  end
27
27
 
28
28
  def _permissions_assignment(exec = :assign, actions, obj)
29
- if actions.first.is_a?(i_am_i_can.permission_model)
29
+ if actions.flatten!.first.is_a?(i_am_i_can.permission_model)
30
30
  exec_arg, names = actions, actions.map(&:name)
31
31
  else
32
32
  objs = obj ? Array(obj) : [nil]
33
- permissions = actions.product(objs).map { |(p, o)| { action: p, **deconstruct_obj(o) } }
34
- exec_arg = permissions.reduce({ }) { |a, b| a.merge(b) { |_, x, y| [x, y] } }
35
- names = permissions.map { |pms| pms.values.compact.join('_').to_sym }
33
+ permissions = actions.product(objs).map { |(p, o)| { action: p, **deconstruct_obj(o) }.values }
34
+ exec_arg = { action: permissions.map(&:first), obj_type: permissions.map { |v| v[1] }, obj_id: permissions.map(&:last) }
35
+ names = permissions.map { |pms| pms.compact.join('_').to_sym }
36
36
  end
37
37
 
38
38
  assignment = _stored_permissions_exec(exec, exec_arg)
@@ -2,9 +2,11 @@ module IAmICan
2
2
  module Permission
3
3
  module Definition
4
4
  def have_permission *actions, obj: nil, remarks: nil
5
- permissions = actions.product(Array[obj]).map { |(p, o)| { action: p, **deconstruct_obj(o), remarks: remarks } }
5
+ return unless actions.flatten!.first.class.in?([ Symbol, String ])
6
+ objs = obj ? Array(obj) : [nil]
7
+ permissions = actions.product(objs).map { |(p, o)| { action: p, **deconstruct_obj(o), remarks: remarks } }
6
8
  definition = _create_permissions(permissions)
7
- ResultOf.roles definition, i_am_i_can, given: permissions.map { |pms| pms.values.compact.join('_').to_sym }
9
+ ResultOf.permissions definition, i_am_i_can, given: permissions.map { |pms| pms.values.compact.join('_').to_sym }
8
10
  end
9
11
 
10
12
  %i[ have_permissions has_permission has_permissions ].each { |aname| alias_method aname, :have_permission }
@@ -37,11 +37,11 @@ module IAmICan
37
37
  def _roles_assignment(action = :assign, roles, save, exp: nil)
38
38
  instances, names = Role.extract(roles, i_am_i_can)
39
39
  if save
40
- assignment = _stored_roles_exec(action, instances, name: names)
40
+ assignment = _stored_roles_exec(action.flatten!, instances, name: names)
41
41
  _set_roles_expire(exp, assignment.map(&:id)) if exp
42
42
  else
43
43
  to_be_assigned_names = (instances.map(&:name).map(&:to_sym) + names).uniq
44
- assignment = _temporary_roles_exec(action, to_be_assigned_names)
44
+ assignment = _temporary_roles_exec(action.flatten!, to_be_assigned_names)
45
45
  end
46
46
 
47
47
  ResultOf.role assignment, i_am_i_can, given: [instances, names]
@@ -2,7 +2,7 @@ module IAmICan
2
2
  module Role
3
3
  module Definition
4
4
  def have_role *roles, which_can: [ ], obj: nil, remarks: nil
5
- return unless roles.first.class.in?([ Symbol, String ])
5
+ return unless roles.flatten!.first.class.in?([ Symbol, String ])
6
6
  roles.map!(&:to_sym) ; i = i_am_i_can
7
7
  definition = _create_roles(roles.map { |role| { name: role, remarks: remarks } })
8
8
 
@@ -3,7 +3,7 @@ module IAmICan
3
3
  module Definition
4
4
  def group_roles *members, by_name:, which_can: [ ], obj: nil
5
5
  group = (i = i_am_i_can).role_group_model.where(name: by_name).first_or_create
6
- instances, names = Role.extract(members, i)
6
+ instances, names = Role.extract(members.flatten!, i)
7
7
  assignment = group._members_exec(:assign, instances, name: names)
8
8
  ResultOf.members assignment, i, given: [instances, names]
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module IAmICan
2
- VERSION = '4.3.0'
2
+ VERSION = '4.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i_am_i_can
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhandao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-16 00:00:00.000000000 Z
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler