poro_validator 0.2.2 → 0.2.3
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/lib/poro_validator/errors.rb +1 -1
- data/lib/poro_validator/validator.rb +3 -3
- data/lib/poro_validator/version.rb +1 -1
- data/poro_validator.gemspec +1 -0
- data/spec/features/reuse_validator_spec.rb +53 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc2ce1f9233a5b88631a5e1f5ecb5335ac2f4a5d
|
4
|
+
data.tar.gz: a57b11e741fbd0a9fa098b7f3f1836641591a1ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653ecf3ec4b6cb90db58f483894aab76c8632f34cc5a15bacdf266817ccedf52923288b318d5155b025d9f140c1b7cccfd169ea55ef927b8a7a668161458e4f2
|
7
|
+
data.tar.gz: 341ec4635211d5d825a5253d2172997d1d97fe6be5195a827c9f0d3a12916434dca46a72bd4cce1cd20e1f8f04ca04e92ad553b2385b2247b545aedcf4013e12
|
@@ -63,7 +63,7 @@ module PoroValidator
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def errors
|
66
|
-
@errors
|
66
|
+
@errors
|
67
67
|
end
|
68
68
|
|
69
69
|
def valid?(entity)
|
@@ -78,8 +78,8 @@ module PoroValidator
|
|
78
78
|
private
|
79
79
|
|
80
80
|
def validate_entity(entity)
|
81
|
-
errors.
|
82
|
-
context = Context.new(entity, self, errors)
|
81
|
+
@errors = PoroValidator::Errors.new
|
82
|
+
context = Context.new(entity, self, @errors)
|
83
83
|
self.class.validations.run_validations(context)
|
84
84
|
end
|
85
85
|
end
|
data/poro_validator.gemspec
CHANGED
@@ -72,6 +72,7 @@ Gem::Specification.new do |spec|
|
|
72
72
|
spec/features/configurable_error_messages_spec.rb
|
73
73
|
spec/features/inheritable_spec.rb
|
74
74
|
spec/features/nested_validations_spec.rb
|
75
|
+
spec/features/reuse_validator_spec.rb
|
75
76
|
spec/features/validate_hash_object_spec.rb
|
76
77
|
spec/lib/poro_validator/configuration_spec.rb
|
77
78
|
spec/lib/poro_validator/error_store_spec.rb
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Allows initialized validations to be reused", type: :feature do
|
4
|
+
it "allows reuse of the validation class" do
|
5
|
+
widget = Struct.new(:name, :size)
|
6
|
+
validator = Class.new do
|
7
|
+
include PoroValidator.validator
|
8
|
+
|
9
|
+
validates :name, inclusion: 'c'..'d'
|
10
|
+
validates :size, numeric: 2..3
|
11
|
+
end
|
12
|
+
|
13
|
+
widgets = ('a'..'d').map.with_index(1) do |n, s|
|
14
|
+
widget.new(n, s)
|
15
|
+
end
|
16
|
+
|
17
|
+
wv = validator.new
|
18
|
+
errors = widgets.map { |w| wv.valid?(w); wv.errors }
|
19
|
+
expect(
|
20
|
+
errors.map(&:empty?)
|
21
|
+
).to eq([false, false, true, false])
|
22
|
+
end
|
23
|
+
|
24
|
+
# Story:
|
25
|
+
# @pid
|
26
|
+
# Widget = Struct.new(:name, :size)
|
27
|
+
#
|
28
|
+
# class WV
|
29
|
+
# include PoroValidator.validator
|
30
|
+
# validates :name, inclusion: 'c'..'d'
|
31
|
+
# validates :size, numeric: 2..3
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# widgets = ('a'..'d').map.with_index(1) do |n, s|
|
35
|
+
# Widget.new(n, s)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # actual validity:
|
39
|
+
# aaa = widgets.map { |w| WV.new.valid?(w) }
|
40
|
+
# puts aaa.join(" ")
|
41
|
+
# #=> [false, false, true, false]
|
42
|
+
#
|
43
|
+
# # but when reusing a validator instance:
|
44
|
+
# wv = WV.new
|
45
|
+
# errors = widgets.map { |w| wv.valid?(w); wv.errors }
|
46
|
+
# puts (errors.map(&:empty?)).join(" ")
|
47
|
+
# #=> [false, false, false, false]
|
48
|
+
#
|
49
|
+
# require 'pry'; binding.pry
|
50
|
+
# # because:
|
51
|
+
# widgets.map { |w| wv.valid?(w); wv.errors.object_id }.uniq.size
|
52
|
+
# #=> 1
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poro_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kareem Gan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- spec/features/configurable_error_messages_spec.rb
|
152
152
|
- spec/features/inheritable_spec.rb
|
153
153
|
- spec/features/nested_validations_spec.rb
|
154
|
+
- spec/features/reuse_validator_spec.rb
|
154
155
|
- spec/features/validate_hash_object_spec.rb
|
155
156
|
- spec/lib/poro_validator/configuration_spec.rb
|
156
157
|
- spec/lib/poro_validator/error_store_spec.rb
|