valcro 0.1 → 0.2.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 +7 -0
- data/.travis.yml +3 -4
- data/lib/valcro/error_list.rb +4 -0
- data/lib/valcro/runner.rb +5 -0
- data/lib/valcro/version.rb +1 -1
- data/lib/valcro.rb +7 -2
- data/spec/error_list_spec.rb +15 -4
- data/spec/runner_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/valcro_spec.rb +49 -4
- data/valcro.gemspec +1 -0
- metadata +40 -29
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d0b163e4ce4b3622845484854e1d18cb2da5c979a6d7553ac4dafddbf3a30b53
|
|
4
|
+
data.tar.gz: 755ae121491f4a852b2aa98ac57f167a411b93d4f8626ed99d2fea8e76bcca18
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 635a3e342da795569d4ed2998c7a719d308fccb66d9fde5783328d03d5e65bbb4a4ce622f62111b20239909c56e102065e1e9c03e81e721daec06a96b1df3b5a
|
|
7
|
+
data.tar.gz: 68e7c8ff05dd6543efdb7916c6a495ae7ad66fb2c38c708a8cc97b0681864356716d7b9d6f8b0807ddd115867dd4835de66bc9835143f216cced8d630da11af9
|
data/.travis.yml
CHANGED
data/lib/valcro/error_list.rb
CHANGED
data/lib/valcro/runner.rb
CHANGED
data/lib/valcro/version.rb
CHANGED
data/lib/valcro.rb
CHANGED
|
@@ -20,9 +20,14 @@ module Valcro
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def validate
|
|
23
|
-
|
|
23
|
+
validation_runner.clear!
|
|
24
24
|
self.class.validators.each do |validator_class|
|
|
25
|
-
|
|
25
|
+
validator = if validator_class.respond_to?(:build)
|
|
26
|
+
validator_class.build(self)
|
|
27
|
+
else
|
|
28
|
+
validator_class.new(self)
|
|
29
|
+
end
|
|
30
|
+
validation_runner.add_validator validator
|
|
26
31
|
end
|
|
27
32
|
self.class.validation_blocks.each do |validation_block|
|
|
28
33
|
instance_eval(&validation_block)
|
data/spec/error_list_spec.rb
CHANGED
|
@@ -51,10 +51,21 @@ describe Valcro::ErrorList, '#any?' do
|
|
|
51
51
|
it 'is true when there are errors 'do
|
|
52
52
|
list = Valcro::ErrorList.new
|
|
53
53
|
|
|
54
|
-
expect(list.any?).to
|
|
54
|
+
expect(list.any?).to be_falsey
|
|
55
55
|
list.add :prop, 'some error'
|
|
56
56
|
|
|
57
|
-
expect(list.any?).to
|
|
57
|
+
expect(list.any?).to be_truthy
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe Valcro::ErrorList, '#none?' do
|
|
62
|
+
it 'is true when there no errors 'do
|
|
63
|
+
list = Valcro::ErrorList.new
|
|
64
|
+
|
|
65
|
+
expect(list.none?).to be_truthy
|
|
66
|
+
list.add :prop, 'some error'
|
|
67
|
+
|
|
68
|
+
expect(list.none?).to be_falsey
|
|
58
69
|
end
|
|
59
70
|
end
|
|
60
71
|
|
|
@@ -62,9 +73,9 @@ describe Valcro::ErrorList, '#clear!' do
|
|
|
62
73
|
it 'removes all errors' do
|
|
63
74
|
list = Valcro::ErrorList.new
|
|
64
75
|
list.add :prop, 'some error'
|
|
65
|
-
expect(list.any?).to
|
|
76
|
+
expect(list.any?).to be_truthy
|
|
66
77
|
|
|
67
78
|
list.clear!
|
|
68
|
-
expect(list.any?).to
|
|
79
|
+
expect(list.any?).to be_falsey
|
|
69
80
|
end
|
|
70
81
|
end
|
data/spec/runner_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/valcro_spec.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe Valcro do
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
it 'is valid with no validations defined' do
|
|
9
|
-
expect(TestClass.new.valid?).to
|
|
9
|
+
expect(TestClass.new.valid?).to be_truthy
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -68,6 +68,51 @@ describe Valcro, 'validators' do
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
describe Valcro, 'reusable validators' do
|
|
72
|
+
class ScopedStatusFailValidator
|
|
73
|
+
def self.build(context)
|
|
74
|
+
new(context.status)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def initialize(status)
|
|
78
|
+
@status = status
|
|
79
|
+
end
|
|
80
|
+
def call(errors)
|
|
81
|
+
errors.add(:status, 'big mistake') if @status == 'fail'
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
let(:test_class) do
|
|
86
|
+
Class.new do
|
|
87
|
+
include Valcro
|
|
88
|
+
attr_accessor :status
|
|
89
|
+
def status
|
|
90
|
+
@status ||= "fail"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
validates_with ScopedStatusFailValidator
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'can be added validators' do
|
|
98
|
+
test_instance = test_class.new
|
|
99
|
+
|
|
100
|
+
test_instance.validate
|
|
101
|
+
expect(test_instance).not_to be_valid
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'clears validations on subsequent runs' do
|
|
105
|
+
test_instance = test_class.new
|
|
106
|
+
|
|
107
|
+
test_instance.validate
|
|
108
|
+
expect(test_instance).not_to be_valid
|
|
109
|
+
|
|
110
|
+
test_instance.status = 'win'
|
|
111
|
+
test_instance.validate
|
|
112
|
+
expect(test_instance).to be_valid
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
71
116
|
describe Valcro, '#error_messages' do
|
|
72
117
|
let(:test_class) do
|
|
73
118
|
Class.new { include Valcro }
|
|
@@ -75,7 +120,7 @@ describe Valcro, '#error_messages' do
|
|
|
75
120
|
|
|
76
121
|
it 'delegates to errors' do
|
|
77
122
|
test_instance = test_class.new
|
|
78
|
-
test_instance.
|
|
123
|
+
allow(test_instance).to receive(:errors).and_return(double(to_s: 'some errors'))
|
|
79
124
|
|
|
80
125
|
expect(test_instance.error_messages).to eq('some errors')
|
|
81
126
|
end
|
|
@@ -96,10 +141,10 @@ describe Valcro, '.validate' do
|
|
|
96
141
|
test_instance = test_class.new
|
|
97
142
|
test_instance.works = false
|
|
98
143
|
test_instance.validate
|
|
99
|
-
expect(test_instance.valid?).to
|
|
144
|
+
expect(test_instance.valid?).to be_falsey
|
|
100
145
|
|
|
101
146
|
test_instance.works = true
|
|
102
147
|
test_instance.validate
|
|
103
|
-
expect(test_instance.valid?).to
|
|
148
|
+
expect(test_instance.valid?).to be_truthy
|
|
104
149
|
end
|
|
105
150
|
end
|
data/valcro.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: valcro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.2.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Harold Giménez
|
|
9
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rspec
|
|
16
|
-
requirement:
|
|
17
|
-
none: false
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - ">="
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
19
|
version: '0'
|
|
22
20
|
type: :development
|
|
23
21
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec-collection_matchers
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
25
41
|
- !ruby/object:Gem::Dependency
|
|
26
42
|
name: rake
|
|
27
|
-
requirement:
|
|
28
|
-
none: false
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
44
|
requirements:
|
|
30
|
-
- -
|
|
45
|
+
- - ">="
|
|
31
46
|
- !ruby/object:Gem::Version
|
|
32
47
|
version: '0'
|
|
33
48
|
type: :development
|
|
34
49
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
36
55
|
description: Valcro is a validation library for arbitrary ruby objects. I's primary
|
|
37
56
|
goal is to remain as simple as possible so that it can be useful to a large surface
|
|
38
57
|
of use cases remaining easily extensible.
|
|
@@ -42,8 +61,8 @@ executables: []
|
|
|
42
61
|
extensions: []
|
|
43
62
|
extra_rdoc_files: []
|
|
44
63
|
files:
|
|
45
|
-
- .gitignore
|
|
46
|
-
- .travis.yml
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- ".travis.yml"
|
|
47
66
|
- Gemfile
|
|
48
67
|
- LICENSE
|
|
49
68
|
- README.md
|
|
@@ -61,33 +80,25 @@ files:
|
|
|
61
80
|
- valcro.gemspec
|
|
62
81
|
homepage: https://github.com/hgimenez/valcro
|
|
63
82
|
licenses: []
|
|
64
|
-
|
|
83
|
+
metadata: {}
|
|
84
|
+
post_install_message:
|
|
65
85
|
rdoc_options: []
|
|
66
86
|
require_paths:
|
|
67
87
|
- lib
|
|
68
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
|
-
none: false
|
|
70
89
|
requirements:
|
|
71
|
-
- -
|
|
90
|
+
- - ">="
|
|
72
91
|
- !ruby/object:Gem::Version
|
|
73
92
|
version: '0'
|
|
74
|
-
segments:
|
|
75
|
-
- 0
|
|
76
|
-
hash: -54788049467793668
|
|
77
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
-
none: false
|
|
79
94
|
requirements:
|
|
80
|
-
- -
|
|
95
|
+
- - ">="
|
|
81
96
|
- !ruby/object:Gem::Version
|
|
82
97
|
version: '0'
|
|
83
|
-
segments:
|
|
84
|
-
- 0
|
|
85
|
-
hash: -54788049467793668
|
|
86
98
|
requirements: []
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
specification_version: 3
|
|
99
|
+
rubygems_version: 3.4.12
|
|
100
|
+
signing_key:
|
|
101
|
+
specification_version: 4
|
|
91
102
|
summary: The simplest possible validation library for Ruby
|
|
92
103
|
test_files:
|
|
93
104
|
- spec/error_list_spec.rb
|