bizness 0.7.0 → 0.8.0

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: ac397c6a08c4dd66a3f50a7fe2f5f7611ca50495
4
- data.tar.gz: 1f37cf2e9e7a5a0e949f6ed9c9735459ab100405
3
+ metadata.gz: 6599bbc343ef41b029d10213194246af4bf30afd
4
+ data.tar.gz: 60a1e05ced98e4e7f0856fb49f5f6bd82f82280e
5
5
  SHA512:
6
- metadata.gz: 069c309dea1de0c942e95afe8112dda7d8b7dccded8034c2d11144f5e58b6e502495fae69e232eea8fa961ac5c7e6fa4740751f916af5706de60c798ce52c2e5
7
- data.tar.gz: 63e95eb213397a8d0908c1fe0232af435b0a9de5d591ed93efdbaec9093d45615dc01b12807e7037442dbbe9020cd2e95901433b9a63e5509bacbeb73c422eb9
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.successful?
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 `successful?` method which does the following when called:
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
 
@@ -33,9 +33,12 @@
33
33
  # Example usage:
34
34
  #
35
35
  # policy = StringFormatPolicy.new("abcd")
36
- # policy.successful?
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 successful?
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("?")}"
@@ -1,3 +1,3 @@
1
1
  module Bizness
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bizness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShippingEasy