i_am_i_can 3.0.0 → 3.0.1

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: 2cda6740e5fdc39a1bf281df8ec61425d001171a
4
- data.tar.gz: 263b17f70ce6ff0fdfdfff8338a85b798e43b500
3
+ metadata.gz: 56545e764dcd1ae9cae7fc388f12df0db09c7628
4
+ data.tar.gz: c8dc0126bdd98e472472cb6a105442979a19ef86
5
5
  SHA512:
6
- metadata.gz: b6d4f29d6565b394bce3d01ddab46f2532d307b093318b5a9cc01e8ce1746edbc3dbe0616403a9a1ab96b05403ac02b933fb90c0f089d99e0746d9efb1040897
7
- data.tar.gz: a545727532511dbb469b0057b5160764442896f9c10d0705a43ce13b40b1bb4c55d3b40be3579449804b653a904cbf5e48ecbcbb6d38472f0ff8bde4d6f45497
6
+ metadata.gz: fea3768f4b9d4391cb2fb7b0c2be7dfe7f553ead20e004bfdea97ad1a50366b85eb02ebbf905a9d85b72dab2fe4c344c1db58ba23e67bb71ee2d80bbe0c3ddc2
7
+ data.tar.gz: aa61ca4f7801fc754cb9b3516a1168de3779ad5c9a6205eb2f18f52acca4d10d0686d71e4e9907553ac50d54e5e4dc612478b07b8f5bb82903cd12473947d27c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i_am_i_can (3.0.0)
4
+ i_am_i_can (3.0.1)
5
5
  activerecord
6
6
  activesupport
7
7
  railties
data/README.md CHANGED
@@ -136,7 +136,7 @@ Resource.that_allow(user).to(:manage) # => Active::Relation
136
136
  has_and_belongs_to_many :stored_roles,
137
137
  join_table: 'users_and_user_roles', foreign_key: 'user_role_id', class_name: 'UserRole', association_foreign_key: 'user_id'
138
138
 
139
- act_as_subject
139
+ acts_as_subject
140
140
  end
141
141
  ```
142
142
 
@@ -55,12 +55,14 @@ module IAmICan
55
55
  end
56
56
 
57
57
  def tips
58
- puts " Add the code below to #{name_c}:".green
58
+ puts "\nAdd the code below to #{name_c}:".green
59
59
  puts <<~TIPS
60
- has_and_belongs_to_many :stored_roles,
61
- join_table: '#{subj_role_tb}', foreign_key: '#{role_u}_id', class_name: '#{role_c}', association_foreign_key: '#{name_u}_id'
62
-
63
- act_as_subject
60
+ |
61
+ | has_and_belongs_to_many :stored_roles,
62
+ | join_table: '#{subj_role_tb}', foreign_key: '#{role_u}_id', class_name: '#{role_c}', association_foreign_key: '#{name_u}_id'
63
+ |
64
+ | acts_as_subject
65
+ |
64
66
  TIPS
65
67
  end
66
68
 
@@ -85,9 +87,9 @@ module IAmICan
85
87
  def permission_up; @ii_opts[:permission_class].underscore.pluralize end
86
88
 
87
89
  def subj_role_tb; name_up + '_and_' + role_up end
88
- def group_role_tb; group_up + '_and_' + role_up end
90
+ def group_role_tb; group_up + '_and_' + role_up rescue nil end
89
91
  def role_pms_tb; role_up + '_and_' + permission_up end
90
- def group_pms_tb; group_up + '_and_' + permission_up end
92
+ def group_pms_tb; group_up + '_and_' + permission_up rescue nil end
91
93
  end
92
94
  end
93
95
  end
@@ -3,6 +3,6 @@ IAmICan::Configs.set_for(subject: '<%= name_c %>',
3
3
  permission: '<%= @ii_opts[:permission_class] %>'<% unless @ii_opts[:without_group] %>,
4
4
  role_group: '<%= @ii_opts[:role_group_class] %>'<% end %>) do |config|
5
5
  <% @ii_opts.except(:role_class, :permission_class, :role_group_class).each do |k, v| %>
6
- <%= "config.#{k} = " %><%= v %>
6
+ <%= "config.#{k} = " %><%= v %>
7
7
  <% end %>
8
8
  end
@@ -7,8 +7,9 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
7
7
  t.timestamps
8
8
  end
9
9
 
10
- add_index :<%= role_up %>, :name,
11
- unique: true, name: '<%= role_up %>_unique_index', using: :btree
10
+ add_index :<%= role_up %>, :name, unique: true, name: '<%= role_up %>_unique_index'
11
+
12
+ # === end of role table ===
12
13
  <% unless @ii_opts[:without_group] %>
13
14
  create_table :<%= group_up %>, force: :cascade do |t|
14
15
  t.string :name, null: false
@@ -17,8 +18,10 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
17
18
  t.timestamps
18
19
  end
19
20
 
20
- add_index :<%= group_up %>, :name,
21
- unique: true, name: '<%= group_up %>_unique_index', using: :btree
21
+ add_index :<%= group_up %>, :name, unique: true, name: '<%= group_up %>_unique_index'
22
+
23
+ # === end of role group table ===
24
+
22
25
  <% end %>
23
26
  create_table :<%= permission_up %>, force: :cascade do |t|
24
27
  t.string :pred, null: false
@@ -29,8 +32,11 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
29
32
  t.timestamps
30
33
  end
31
34
 
32
- add_index :<%= permission_up %>, %i[ pred obj_type obj_id ],
33
- unique: true, name: '<%= permission_up %>_unique_index', using: :btree
35
+ add_index :<%= permission_up %>, %i[ pred obj_type obj_id ], unique: true, name: '<%= permission_up %>_unique_index'
36
+ ### Open below if you want to use `Resource.that_allow` frequently
37
+ # add_index :<%= permission_up %>, %i[ pred obj_type ], name: '<%= permission_up %>_resource_search_index'
38
+
39
+ # === end of permission table ===
34
40
 
35
41
  create_table :<%= subj_role_tb %>, id: false, force: :cascade do |t|
36
42
  t.belongs_to :<%= name_u %>, null: false#, index: false
@@ -41,6 +47,8 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
41
47
  # add_index :<%= subj_role_tb %>, :<%= role_u %>_id, name: ':<%= subj_role_tb %>_index2'
42
48
  add_index :<%= subj_role_tb %>, [ :<%= name_u %>_id, :<%= role_u %>_id ],
43
49
  unique: true, name: '<%= subj_role_tb %>_uniq_index'
50
+
51
+ # === end of subject-role table ===
44
52
  <% unless @ii_opts[:without_group] %>
45
53
  create_table :<%= group_role_tb %>, id: false, force: :cascade do |t|
46
54
  t.belongs_to :<%= group_u %>, null: false#, index: false
@@ -52,6 +60,8 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
52
60
  add_index :<%= group_role_tb %>, [ :<%= group_u %>_id, :<%= role_u %>_id ],
53
61
  unique: true, name: '<%= group_role_tb %>_uniq_index'
54
62
 
63
+ # === end of group-role table ===
64
+
55
65
  <% end %>
56
66
  create_table :<%= role_pms_tb %>, id: false, force: :cascade do |t|
57
67
  t.belongs_to :<%= role_u %>, null: false#, index: false
@@ -62,6 +72,8 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
62
72
  # add_index :<%= role_pms_tb %>, :<%= permission_u %>_id, name: '<%= role_pms_tb %>_index2'
63
73
  add_index :<%= role_pms_tb %>, [ :<%= role_u %>_id, :<%= permission_u %>_id ],
64
74
  unique: true, name: '<%= role_pms_tb %>_uniq_index'
75
+
76
+ # === end of role-permission table ===
65
77
  <% unless @ii_opts[:without_group] %>
66
78
  create_table :<%= group_pms_tb %>, id: false, force: :cascade do |t|
67
79
  t.belongs_to :<%= group_u %>, null: false#, index: false
@@ -73,6 +85,8 @@ class <%= name_c %>Am<%= name_c %>Can < ActiveRecord::Migration::Current
73
85
  add_index :<%= group_pms_tb %>, [ :<%= group_u %>_id, :<%= permission_u %>_id ],
74
86
  unique: true, name: '<%= group_pms_tb %>_uniq_index'
75
87
 
88
+ # === end of group-permission table ===
89
+
76
90
  <% end %>
77
91
  end
78
92
  end
@@ -5,7 +5,7 @@ class <%= permission_c %> < ActiveRecord::Base
5
5
  has_and_belongs_to_many :related_role_groups,
6
6
  join_table: '<%= group_pms_tb %>', foreign_key: :<%= group_u %>_id, class_name: '<%= group_c %>', association_foreign_key: :<%= permission_u %>_id
7
7
  <% end %>
8
- act_as_permission
8
+ acts_as_permission
9
9
  end
10
10
 
11
11
  __END__
@@ -8,7 +8,7 @@ class <%= role_c %> < ActiveRecord::Base
8
8
  has_and_belongs_to_many :stored_permissions,
9
9
  join_table: '<%= role_pms_tb %>', foreign_key: :<%= permission_u %>_id, class_name: '<%= permission_c %>', association_foreign_key: :<%= role_u %>_id
10
10
 
11
- act_as_role
11
+ acts_as_role
12
12
 
13
13
  # default_scope { with_stored_permissions }
14
14
  end
@@ -5,7 +5,7 @@ class RoleGroup < ActiveRecord::Base
5
5
  has_and_belongs_to_many :members,
6
6
  join_table: '<%= group_role_tb %>', foreign_key: :<%= role_u %>_id, class_name: '<%= role_c %>', association_foreign_key: :<%= group_u %>_id
7
7
 
8
- act_as_role_group
8
+ acts_as_role_group
9
9
 
10
10
  # default_scope { with_members.with_stored_permissions) }
11
11
  end
@@ -22,7 +22,7 @@ module IAmICan
22
22
  def to(pred)
23
23
  roles = Configs.take.subject_model._roles
24
24
  permissions = Configs.take.role_model._permissions
25
- allowed_ids = subject.send(roles).send(permissions).where(pred: pred, obj_type: records.name).pluck(:obj_id)
25
+ allowed_ids = subject.send(roles).send(permissions).where(pred: pred, obj_type: records.name).pluck(:obj_id).uniq
26
26
  records.where(id: allowed_ids)
27
27
  end
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module IAmICan
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
data/lib/i_am_i_can.rb CHANGED
@@ -12,7 +12,7 @@ require 'i_am_i_can/subject'
12
12
  require 'i_am_i_can/resource'
13
13
 
14
14
  module IAmICan
15
- def act_as_subject
15
+ def acts_as_subject
16
16
  i_am_i_can.act = :subject
17
17
  include Subject
18
18
 
@@ -27,7 +27,7 @@ module IAmICan
27
27
  instance_exec(%i[ role ], &DynamicGenerate.assignment_helpers)
28
28
  end
29
29
 
30
- def act_as_role
30
+ def acts_as_role
31
31
  i_am_i_can.act = :role
32
32
  include Role
33
33
 
@@ -40,7 +40,7 @@ module IAmICan
40
40
  instance_exec(%i[ permission ], &DynamicGenerate.assignment_helpers)
41
41
  end
42
42
 
43
- def act_as_role_group
43
+ def acts_as_role_group
44
44
  i_am_i_can.act = :role_group
45
45
  include Role
46
46
 
@@ -53,7 +53,7 @@ module IAmICan
53
53
  instance_exec(%i[ role permission ], &DynamicGenerate.assignment_helpers)
54
54
  end
55
55
 
56
- def act_as_permission
56
+ def acts_as_permission
57
57
  i_am_i_can.act = :permission
58
58
  include Permission
59
59
 
@@ -62,7 +62,7 @@ module IAmICan
62
62
  instance_exec(&DynamicGenerate.class_reflections)
63
63
  end
64
64
 
65
- def act_as_allowed_resource
65
+ def acts_as_allowed_resource
66
66
  include Resource
67
67
  end
68
68
 
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: 3.0.0
4
+ version: 3.0.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-10-23 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler