action_policy 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/action_policy.rb +2 -0
- data/lib/action_policy/policy/aliases.rb +8 -0
- data/lib/action_policy/policy/core.rb +9 -2
- data/lib/action_policy/utils/pretty_print.rb +2 -2
- data/lib/action_policy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e859b71805cff1035904f6a6b6ec73e19f4722e894f88b9a7834a30569c4f587
|
4
|
+
data.tar.gz: 2df569e93f84268bf3244d1615559716b16081d53df826dfe856cefb7dd0becc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6457503550706d1cc63e4e636c675f9d7a0f70184deb0217a8ad79206c897e00317eef14522a72c415b8e292ee0d52a9837c011e2793cec1eee55e8ed792f778
|
7
|
+
data.tar.gz: 148141b42a80097b3b7369118027b77a8cd7a1412cef4b3cd75f5e80415c93cd60f1d1a5d3fd1ee0f30f44886475f59db408deffa3c40d060ff3319fef45c1b9
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.5.6 (2021-03-03)
|
6
|
+
|
7
|
+
- Add `ActionPolicy.enforce_predicate_rules_naming` config to catch rule missing question mark ([@skojin][])
|
8
|
+
|
5
9
|
## 0.5.5 (2020-12-28)
|
6
10
|
|
7
11
|
- Upgrade to Ruby 3.0. ([@palkan][])
|
@@ -440,3 +444,4 @@ This value is now stored in a cache (if any) instead of just the call result (`t
|
|
440
444
|
[@somenugget]: https://github.com/somenugget
|
441
445
|
[@Be-ngt-oH]: https://github.com/Be-ngt-oH
|
442
446
|
[@pirj]: https://github.com/pirj
|
447
|
+
[@skojin]: https://github.com/skojin
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2018-
|
3
|
+
Copyright (c) 2018-2021 Vladimir Dementyev
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
data/lib/action_policy.rb
CHANGED
@@ -34,6 +34,8 @@ module ActionPolicy
|
|
34
34
|
class << self
|
35
35
|
attr_accessor :cache_store
|
36
36
|
|
37
|
+
attr_accessor :enforce_predicate_rules_naming
|
38
|
+
|
37
39
|
# Find a policy class for a target
|
38
40
|
def lookup(target, allow_nil: false, default: nil, **options)
|
39
41
|
LookupChain.call(target, **options) ||
|
@@ -31,10 +31,18 @@ module ActionPolicy
|
|
31
31
|
def resolve_rule(activity)
|
32
32
|
self.class.lookup_alias(activity) ||
|
33
33
|
(activity if respond_to?(activity)) ||
|
34
|
+
(check_rule_naming(activity) if ActionPolicy.enforce_predicate_rules_naming) ||
|
34
35
|
self.class.lookup_default_rule ||
|
35
36
|
super
|
36
37
|
end
|
37
38
|
|
39
|
+
private def check_rule_naming(activity)
|
40
|
+
unless activity[-1] == "?"
|
41
|
+
raise NonPredicateRule.new(self, activity)
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
38
46
|
module ClassMethods # :nodoc:
|
39
47
|
def default_rule(val)
|
40
48
|
rules_aliases[DEFAULT] = val
|
@@ -23,12 +23,19 @@ module ActionPolicy
|
|
23
23
|
def initialize(policy, rule)
|
24
24
|
@policy = policy.class
|
25
25
|
@rule = rule
|
26
|
-
@message =
|
27
|
-
"Couldn't find rule '#{@rule}' for #{@policy}" \
|
26
|
+
@message = "Couldn't find rule '#{@rule}' for #{@policy}" \
|
28
27
|
"#{suggest(@rule, @policy.instance_methods - Object.instance_methods)}"
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
31
|
+
class NonPredicateRule < UnknownRule
|
32
|
+
def initialize(policy, rule)
|
33
|
+
@policy = policy.class
|
34
|
+
@rule = rule
|
35
|
+
@message = "The rule '#{@rule}' of '#{@policy}' must ends with ? (question mark)\nDid you mean? #{@rule}?"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
32
39
|
module Policy
|
33
40
|
# Core policy API
|
34
41
|
module Core
|
@@ -146,8 +146,8 @@ module ActionPolicy
|
|
146
146
|
|
147
147
|
def colorize(val)
|
148
148
|
return val unless $stdout.isatty
|
149
|
-
return TRUE if val.eql?(true)
|
150
|
-
return FALSE if val.eql?(false)
|
149
|
+
return TRUE if val.eql?(true) # rubocop:disable Lint/DeprecatedConstants
|
150
|
+
return FALSE if val.eql?(false) # rubocop:disable Lint/DeprecatedConstants
|
151
151
|
val
|
152
152
|
end
|
153
153
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: ruby-next
|
14
|
+
name: ruby-next
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|