bizness 0.7.0 → 0.8.0
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 +4 -4
- data/README.md +7 -2
- data/lib/bizness/policy.rb +9 -2
- data/lib/bizness/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6599bbc343ef41b029d10213194246af4bf30afd
|
4
|
+
data.tar.gz: 60a1e05ced98e4e7f0856fb49f5f6bd82f82280e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb2e525513591afec3878242ef25024a4798dde1522c32e9299cbfae899df7843537998c88ac5aa46ceb118b9f81243cc1aad2cd6bb64be930801c5e5b5a8df
|
7
|
+
data.tar.gz: 464f51d50728f652d3ce2f04582bf262ed79e90d572f32845d4ecc0720f9e088a108696c8f7b30c98472d127df3155ecedbd7c7fe8b91e77b160fe455769705e
|
data/README.md
CHANGED
@@ -114,20 +114,25 @@ class Policies::StringFormatPolicy
|
|
114
114
|
end
|
115
115
|
|
116
116
|
policy = Policies::StringFormatPolicy.new(string: "abc123")
|
117
|
-
policy.
|
117
|
+
policy.obeyed?
|
118
118
|
#=> false
|
119
119
|
|
120
|
+
policy.violated?
|
121
|
+
#=> true
|
122
|
+
|
120
123
|
policy.violations
|
121
124
|
#=> ["String must be alphanumeric", "Characters must be all uppercase"]
|
122
125
|
```
|
123
126
|
|
124
|
-
By including the module, the object gets the `
|
127
|
+
By including the module, the object gets the `obeyed?` method which does the following when called:
|
125
128
|
|
126
129
|
1. Introspects all private predicate methods (methods that end with a question mark) and executes them
|
127
130
|
2. If the method returns false, it looks for a translation in an I18n YAML file
|
128
131
|
3. It composes an 118n key using the policy's class and method name (without the question mark). For example: `policies.mock_policy.violations.all_caps`
|
129
132
|
4. It adds the result of the translation to the list of `violations`
|
130
133
|
5. It returns false if any violations are found
|
134
|
+
|
135
|
+
The inverse method `violated?` for `obeyed?` is also included.
|
131
136
|
|
132
137
|
An example I18n translation file looks like this:
|
133
138
|
|
data/lib/bizness/policy.rb
CHANGED
@@ -33,9 +33,12 @@
|
|
33
33
|
# Example usage:
|
34
34
|
#
|
35
35
|
# policy = StringFormatPolicy.new("abcd")
|
36
|
-
# policy.
|
36
|
+
# policy.obeyed?
|
37
37
|
# => false
|
38
38
|
#
|
39
|
+
# policy.violated?
|
40
|
+
# => true
|
41
|
+
#
|
39
42
|
# policy.violations
|
40
43
|
# => ["Must be an uppercase string"]
|
41
44
|
#
|
@@ -48,7 +51,7 @@ module Bizness::Policy
|
|
48
51
|
@violations || []
|
49
52
|
end
|
50
53
|
|
51
|
-
def
|
54
|
+
def obeyed?
|
52
55
|
self.violations = []
|
53
56
|
self.class.__requirements__.each do |m|
|
54
57
|
self.violations << self.class.violation_message(m) unless send(m)
|
@@ -56,6 +59,10 @@ module Bizness::Policy
|
|
56
59
|
violations.empty?
|
57
60
|
end
|
58
61
|
|
62
|
+
def violated?
|
63
|
+
!obeyed?
|
64
|
+
end
|
65
|
+
|
59
66
|
module ClassMethods
|
60
67
|
def violation_message(method)
|
61
68
|
message_key = "#{__violation_key_prefix__}.#{method.to_s.delete("?")}"
|
data/lib/bizness/version.rb
CHANGED