cancancan-system 1.0.0 → 1.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
  SHA256:
3
- metadata.gz: 94f86f5710ad3064cb2fbd31f4894fda9bc079b26701f7ed351c5a52ad59821f
4
- data.tar.gz: e81ae0727b09aa9e0a137962c46927c0ca313bdc2480aa964c661fa11e09d882
3
+ metadata.gz: b37daed7b5d3b0c495de6e7bc587dba3d6142f2c7f3eb661b5f18c7af50312f8
4
+ data.tar.gz: dd5d14a8eef306541a19793abddff2a275b6105a60bf0293ab4cde8f91ed7b77
5
5
  SHA512:
6
- metadata.gz: a35d4aac231b628f6b3223b46308719f5916d030f5b5f07d48a502db0ba4cc5c8f717d372b92059c7f556bccae684646ab21b11918608890f1f0b02389c28ecc
7
- data.tar.gz: c88efd88664474247b41b0b2b91672f594140d55f5f3c0d7eed44ba8127d0d541ad926a82f5357aa1f04aafadeaaff4654cc0f351eea0c5be71235f7ec35e080
6
+ metadata.gz: 8e584e80ec587a3eb539e61154a55a7c07ff0106e1a883208517c1cd16676820186c34ecfa49be91ae85faedea0a4ccdcf979ef56050c480e3672b690350df36
7
+ data.tar.gz: 6a9c6657c00a41538b757f7bebccbe30bb768298a6f02a23ea10524f9354c42608876b14ba9800bee7d124ea21a4515f9afddebb285f705e38fddda3a36dde58
@@ -4,6 +4,11 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 1.0.1 - 2018/01/21
8
+
9
+ * bugfixes
10
+ * fixed variable naming issues
11
+
7
12
  ### 1.0.0 - 2018/01/20
8
13
 
9
14
  * initial release
data/README.md CHANGED
@@ -87,6 +87,18 @@ end
87
87
 
88
88
  **Note:** The aliases (`:create, :read, :update, :destroy`) can be custom.
89
89
 
90
+ You should add the `ability` attribute to ActiveRecord models you want to [define abilities](#defining-abilities) for:
91
+
92
+ ```ruby
93
+ add_column :users, :ability, :string, default: 'guest'
94
+ ```
95
+
96
+ And you should add a `visiblity` attribute to ActiveRecord models you want to define [public abilities](#public-abilities) for:
97
+
98
+ ```ruby
99
+ add_column :users, :visiblity, :string, default: 'public'
100
+ ```
101
+
90
102
  ### Defining Abilities
91
103
 
92
104
  CanCanCan System makes an `abilities` method available which simplifies setting up common abilities:
@@ -6,7 +6,7 @@ module CanCanCan
6
6
 
7
7
  def method_missing m, *args
8
8
  if m.to_s[/(.+)_abilities/]
9
- membership_abilities $1, args
9
+ membership_abilities $1, *args
10
10
  else
11
11
  super
12
12
  end
@@ -19,7 +19,7 @@ module CanCanCan
19
19
  private
20
20
 
21
21
  def modify aliases
22
- alias_action aliases, to: :modify
22
+ alias_action *aliases, to: :modify
23
23
  end
24
24
 
25
25
  def abilities record_class, user, options = {}
@@ -37,7 +37,7 @@ module CanCanCan
37
37
  else
38
38
  can :manage, record_class, "#{options[:column]}_id": user.id
39
39
  end
40
- yield
40
+ yield if block_given?
41
41
  end
42
42
  end
43
43
 
@@ -54,24 +54,24 @@ module CanCanCan
54
54
  if belonging.belonger_type == class_name.camelize
55
55
  ability = ability belonging
56
56
  if options[:acts_as_belongable]
57
- can ability, record_class, "#{column || class_name.pluralize}": { id: belonging.belonger_id }
57
+ can ability, record_class, "#{options[:column] || class_name.pluralize}": { id: belonging.belonger_id }
58
58
  else
59
59
  if options[:polymorphic]
60
- can ability, record_class, "#{column || class_name}_id": belonging.belonger_id, "#{column || class_name}_type": belonging.belonger_type
60
+ can ability, record_class, "#{options[:column] || class_name}_id": belonging.belonger_id, "#{options[:column] || class_name}_type": belonging.belonger_type
61
61
  else
62
- can ability, record_class, "#{column || class_name}_id": belonging.belonger_id
62
+ can ability, record_class, "#{options[:column] || class_name}_id": belonging.belonger_id
63
63
  end
64
64
  end
65
65
  end
66
66
  end
67
67
  user.send("#{class_name.pluralize}").each do |object|
68
68
  if options[:acts_as_belongable]
69
- can :manage, record_class, "#{column || class_name.pluralize}": { id: object.id }
69
+ can :manage, record_class, "#{options[:column] || class_name.pluralize}": { id: object.id }
70
70
  else
71
71
  if options[:polymorphic]
72
- can :manage, record_class, "#{column || class_name}_id": object.id, "#{column || class_name}_type": object.class.name
72
+ can :manage, record_class, "#{options[:column] || class_name}_id": object.id, "#{options[:column] || class_name}_type": object.class.name
73
73
  else
74
- can :manage, record_class, "#{column || class_name}_id": object.id
74
+ can :manage, record_class, "#{options[:column] || class_name}_id": object.id
75
75
  end
76
76
  end
77
77
  end
@@ -83,12 +83,12 @@ module CanCanCan
83
83
  }
84
84
  options = defaults.merge options
85
85
 
86
- if scope.nil?
86
+ if options[:scope].nil?
87
87
  user.belongable_belongings.each do |belonging|
88
88
  belongable_belonging belonging
89
89
  end
90
90
  else
91
- user.belongable_belongings.where(scope: scope.to_s).each do |belonging|
91
+ user.belongable_belongings.where(scope: options[:scope].to_s).each do |belonging|
92
92
  belongable_belonging belonging
93
93
  end
94
94
  end
@@ -106,12 +106,12 @@ module CanCanCan
106
106
  }
107
107
  options = defaults.merge options
108
108
 
109
- if scope.nil?
109
+ if options[:scope].nil?
110
110
  user.belonger_belongings.each do |belonging|
111
111
  belonger_belonging belonging
112
112
  end
113
113
  else
114
- user.belonger_belongings.where(scope: scope.to_s).each do |belonging|
114
+ user.belonger_belongings.where(scope: options[:scope].to_s).each do |belonging|
115
115
  belonger_belonging belonging
116
116
  end
117
117
  end
@@ -137,10 +137,8 @@ module CanCanCan
137
137
  :modify
138
138
  when 'guest'
139
139
  :read
140
- when nil
141
- nil
142
140
  else
143
- object.ability.to_sym
141
+ object.ability&.to_sym
144
142
  end
145
143
  end
146
144
 
@@ -1,7 +1,7 @@
1
1
  module CanCanCan
2
2
  module System
3
3
 
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
 
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancancan-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -104,7 +104,7 @@ files:
104
104
  - CHANGELOG.md
105
105
  - LICENSE
106
106
  - README.md
107
- - app/models/concerns/cancancan/system/ability.rb
107
+ - app/models/concerns/can_can_can/system/ability.rb
108
108
  - lib/cancancan-system.rb
109
109
  - lib/cancancan-system/engine.rb
110
110
  - lib/cancancan-system/version.rb