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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ab2a0ee9dbb6cacf404dd00408207233968b22c
4
- data.tar.gz: 5c43eeef7b7be9250b85f3c632648ff9f6cf8ffb
3
+ metadata.gz: bc2ce1f9233a5b88631a5e1f5ecb5335ac2f4a5d
4
+ data.tar.gz: a57b11e741fbd0a9fa098b7f3f1836641591a1ad
5
5
  SHA512:
6
- metadata.gz: d7bd91417be08c22f3a2bedecd8d932ada2e23f3dc6f5b9890a16fbaf2c81ee2cd9d252bece9b0aa4381aa941f70beb4a74d4220c8982cb35a5e4ae56fa24f4c
7
- data.tar.gz: b3967f199b60e1778c94fb5e481532858ce451457d7afe4067dae966df0d645c60ea28b6c4e5f1a71afc4ee0cb498103d911d04d2410f086eba10009c3b5a95a
6
+ metadata.gz: 653ecf3ec4b6cb90db58f483894aab76c8632f34cc5a15bacdf266817ccedf52923288b318d5155b025d9f140c1b7cccfd169ea55ef927b8a7a668161458e4f2
7
+ data.tar.gz: 341ec4635211d5d825a5253d2172997d1d97fe6be5195a827c9f0d3a12916434dca46a72bd4cce1cd20e1f8f04ca04e92ad553b2385b2247b545aedcf4013e12
@@ -40,7 +40,7 @@ module PoroValidator
40
40
  end
41
41
 
42
42
  def clear_errors
43
- store.reset
43
+ self.store.reset
44
44
  end
45
45
 
46
46
  alias_method :[], :on
@@ -63,7 +63,7 @@ module PoroValidator
63
63
  end
64
64
 
65
65
  def errors
66
- @errors ||= ::PoroValidator::Errors.new
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.clear_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
@@ -1,3 +1,3 @@
1
1
  module PoroValidator
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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.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-23 00:00:00.000000000 Z
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