action_policy 0.5.3 → 0.5.4

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: 5e0d9085b8204e1846c9820dbc5eb7a9960fa9c512a51d942cc8aab16b065257
4
- data.tar.gz: c85bf2348affc45eb365200070257bc31b873ded038033a0fb3d6f5ca8adb48d
3
+ metadata.gz: 911b1f7b929d458ae0bb95eb22fa11ff2a17925d9c797b626664bdad82b7abbc
4
+ data.tar.gz: 69bc6ead609db7cbcdc3d31455e7e17b88bf9037a51a8b1722e414a7e50c41e4
5
5
  SHA512:
6
- metadata.gz: 2a1de70b5460eed8dc481a651ea52318e060fb486e604b0595f0fa09a4840a0eb93be2b90b7f20789cb135e62388f00a18650881e9739564ba311d11a3fbd131
7
- data.tar.gz: 5cbcf29add9f224ce3b77a42a17ab403dec7f2f93a581f6ad25e13d8f1e75bc650d9889cb05dd247355fee6b6844fb400852f51b2d1118ac30076e5277b95e75
6
+ metadata.gz: e3cf8e4bd9347f052a34cee11fad004030ee80d9281c6bbbb9fe99b8f6665b0c611661d6ce3be8578345ef3171ad35d2c38fff8936bdd47efef48bb137a5a415
7
+ data.tar.gz: 63c4444667971ee445b60e2d9ffee89402021151ac730f00063f2066984c1ca75c15ae40b45fbce60ce9c4201826116bb417f6e62dbfd91f96a3f3974e26a458
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.5.4 (2020-12-09)
6
+
7
+ - Add support for RSpec aliases detection when linting policy specs with `rubocop-rspec` 2.0 ([@pirj][])
8
+
9
+ - Fix `strict_namespace: true` lookup option not finding policies in global namespace ([@Be-ngt-oH][])
10
+
5
11
  ## 0.5.0 (2020-09-29)
6
12
 
7
13
  - Move `deny!` / `allow!` to core. ([@palkan][])
@@ -37,7 +43,7 @@ This method is similar to `allowed_to?` but returns an authorization result obje
37
43
 
38
44
  Fixes [#122](https://github.com/palkan/action_policy/issues/122).
39
45
 
40
- - Separated `#classify`-based and `#camelize`-based symbol lookups. ([Be-ngt-oH][])
46
+ - Separated `#classify`-based and `#camelize`-based symbol lookups. ([@Be-ngt-oH][])
41
47
 
42
48
  Only affects Rails apps. Now lookup for `:users` tries to find `UsersPolicy` first (camelize),
43
49
  and only then search for `UserPolicy` (classify).
@@ -429,3 +435,4 @@ This value is now stored in a cache (if any) instead of just the call result (`t
429
435
  [@nicolas-brousse]: https://github.com/nicolas-brousse
430
436
  [@somenugget]: https://github.com/somenugget
431
437
  [@Be-ngt-oH]: https://github.com/Be-ngt-oH
438
+ [@pirj]: https://github.com/pirj
@@ -0,0 +1,17 @@
1
+ RSpec:
2
+ Language:
3
+ ExampleGroups:
4
+ Regular:
5
+ - describe_rule
6
+ Focused:
7
+ - fdescribe_rule
8
+ Skipped:
9
+ - xdescribe_rule
10
+ Includes:
11
+ Examples:
12
+ - succeed
13
+ - failed
14
+ - fsucceed
15
+ - ffailed
16
+ - xsucceed
17
+ - xfailed
@@ -36,8 +36,7 @@ module ActionPolicy
36
36
  if strict
37
37
  put_if_absent(:strict, namespace, policy, &block)
38
38
  else
39
- cached_policy = put_if_absent(:strict, namespace, policy, &block)
40
- put_if_absent(:flexible, namespace, policy) { cached_policy }
39
+ put_if_absent(:flexible, namespace, policy, &block)
41
40
  end
42
41
  end
43
42
 
@@ -66,22 +65,17 @@ module ActionPolicy
66
65
  private
67
66
 
68
67
  def lookup_within_namespace(policy_name, namespace, strict: false)
69
- return unless namespace
70
- NamespaceCache.fetch(namespace.name, policy_name, strict: strict) do
68
+ NamespaceCache.fetch(namespace&.name || "Kernel", policy_name, strict: strict) do
71
69
  mod = namespace
72
70
  loop do
73
- policy = "#{mod.name}::#{policy_name}".safe_constantize
74
- break policy unless policy.nil?
71
+ policy = [mod&.name, policy_name].compact.join("::").safe_constantize
72
+ break policy if policy || mod.nil? || strict
73
+
75
74
  mod = mod.namespace
76
- break if mod.nil? || strict
77
75
  end
78
76
  end
79
77
  end
80
78
 
81
- def objectify_policy(policy_name, strict: false)
82
- policy_name.safe_constantize unless strict
83
- end
84
-
85
79
  def policy_class_name_for(record)
86
80
  return record.policy_name.to_s if record.respond_to?(:policy_name)
87
81
 
@@ -110,17 +104,10 @@ module ActionPolicy
110
104
  record.class.policy_class if record.class.respond_to?(:policy_class)
111
105
  }
112
106
 
113
- # Lookup within namespace when provided
114
- NAMESPACE_LOOKUP = ->(record, namespace: nil, **) {
115
- next if namespace.nil?
116
-
117
- policy_name = policy_class_name_for(record)
118
- lookup_within_namespace(policy_name, namespace)
119
- }
120
-
121
107
  # Infer from class name
122
- INFER_FROM_CLASS = ->(record, **) {
123
- policy_class_name_for(record).safe_constantize
108
+ INFER_FROM_CLASS = ->(record, namespace: nil, strict_namespace: false, **) {
109
+ policy_name = policy_class_name_for(record)
110
+ lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
124
111
  }
125
112
 
126
113
  # Infer from passed symbol
@@ -128,8 +115,7 @@ module ActionPolicy
128
115
  next unless record.is_a?(Symbol)
129
116
 
130
117
  policy_name = "#{record.camelize}Policy"
131
- lookup_within_namespace(policy_name, namespace, strict: strict_namespace) ||
132
- objectify_policy(policy_name, strict: strict_namespace)
118
+ lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
133
119
  }
134
120
 
135
121
  # (Optional) Infer using String#classify if available
@@ -137,8 +123,7 @@ module ActionPolicy
137
123
  next unless record.is_a?(Symbol)
138
124
 
139
125
  policy_name = "#{record.to_s.classify}Policy"
140
- lookup_within_namespace(policy_name, namespace, strict: strict_namespace) ||
141
- objectify_policy(policy_name, strict: strict_namespace)
126
+ lookup_within_namespace(policy_name, namespace, strict: strict_namespace)
142
127
  }
143
128
 
144
129
  self.chain = [
@@ -146,7 +131,6 @@ module ActionPolicy
146
131
  (CLASSIFY_SYMBOL_LOOKUP if String.method_defined?(:classify)),
147
132
  INSTANCE_POLICY_CLASS,
148
133
  CLASS_POLICY_CLASS,
149
- NAMESPACE_LOOKUP,
150
134
  INFER_FROM_CLASS
151
135
  ].compact
152
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionPolicy
4
- VERSION = "0.5.3"
4
+ VERSION = "0.5.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core
@@ -132,6 +132,7 @@ files:
132
132
  - CHANGELOG.md
133
133
  - LICENSE.txt
134
134
  - README.md
135
+ - config/rubocop-rspec.yml
135
136
  - lib/.rbnext/2.7/action_policy/behaviours/policy_for.rb
136
137
  - lib/.rbnext/2.7/action_policy/i18n.rb
137
138
  - lib/.rbnext/2.7/action_policy/policy/cache.rb