hash_validator 0.6.0 → 0.7.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: cf1be444ed797f5eb29cf69a168d6954c06ecfe9
4
- data.tar.gz: 4bd3fc6857245aacb1f60e046e5fbb200ab0c5ab
3
+ metadata.gz: 6d59a9fcf0e3e3d923d612488af9ff65634ec245
4
+ data.tar.gz: 5930e9f250b9782b934bb96911af050fcf298caf
5
5
  SHA512:
6
- metadata.gz: dfd2fb4cd260de7e6c5af4c303fef12cc6787707cb2048317a790acdbbebbbbc7f9e8e9ada6603c99b540ceeb995a5f7141b933e0a030c1bead07f5e1d1d2793
7
- data.tar.gz: 0fe4873c5a5fd271ed2fc79d28db3fa90523d1f835845932096faaa23ded1cda2c9f9d301cf4e2d7efca13b87bb090f8d2d69f90e64d1783dbb57fc2a1991c58
6
+ metadata.gz: d027e7bb81c1cd5c5da47d8d50a3c5f5e7fc6d580f28e6e4726d8c6f83d179330a5b7a2826c1d99e383b61d33d1de4a88322de13e124b32cc9a59da2d672e59b
7
+ data.tar.gz: 8f282ee2705a7fd84f63675c1ce186984325a52a5552b4cc449ff04a5fd32514d9a8941452358845570496742d9f8b6fd33308b188d4816a49522b2531b4517b
data/.travis.yml CHANGED
@@ -1,12 +1,6 @@
1
1
  language: ruby
2
- before_install:
3
- - "gem install bundler"
4
- cache: bundler
5
2
  rvm:
6
- - 1.9.2
7
- - 1.9.3
8
3
  - 2.0.0
9
4
  - 2.1.0
10
5
  - 2.2.0
11
6
  - 2.3.0
12
- - jruby-19mode
@@ -0,0 +1,21 @@
1
+ class HashValidator::Validator::RegexpValidator < HashValidator::Validator::Base
2
+ def initialize
3
+ super('_regex') # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator)
4
+ end
5
+
6
+ def should_validate?(rhs)
7
+ rhs.is_a?(Regexp)
8
+ end
9
+
10
+ def presence_error_message
11
+ 'does not match regular expression'
12
+ end
13
+
14
+ def validate(key, value, regexp, errors)
15
+ unless regexp.match(value.to_s)
16
+ errors[key] = presence_error_message
17
+ end
18
+ end
19
+ end
20
+
21
+ HashValidator.append_validator(HashValidator::Validator::RegexpValidator.new)
@@ -31,6 +31,7 @@ require 'hash_validator/validators/simple_type_validators'
31
31
  require 'hash_validator/validators/boolean_validator'
32
32
  require 'hash_validator/validators/email_validator'
33
33
  require 'hash_validator/validators/enumerable_validator'
34
+ require 'hash_validator/validators/regex_validator'
34
35
  require 'hash_validator/validators/lambda_validator'
35
36
  require 'hash_validator/validators/optional_validator'
36
37
  require 'hash_validator/validators/many_validator'
@@ -1,3 +1,3 @@
1
1
  module HashValidator
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -184,7 +184,16 @@ describe HashValidator do
184
184
  end
185
185
 
186
186
  describe 'nested validations' do
187
- let(:validations) {{ foo: 'numeric', bar: 'string', user: { first_name: 'string', age: 'required', likes: 'array' } }}
187
+ let(:validations) {{
188
+ foo: 'numeric',
189
+ bar: 'string',
190
+ user: {
191
+ first_name: 'string',
192
+ last_name: /^(Brooks|Smith)$/,
193
+ age: 'required',
194
+ likes: 'array'
195
+ }
196
+ }}
188
197
 
189
198
  it 'should validate a complex hash' do
190
199
  v = validate(complex_hash, validations)
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Regular expression validator' do
4
+ describe 'Accepting RegExps in validations' do
5
+ it 'should accept a regexp' do
6
+ validate({}, { foo: // })
7
+ end
8
+ end
9
+
10
+ describe '#validate' do
11
+ let(:validations) {{ string: /^foo$/ }}
12
+
13
+ it 'should validate true when the value is foo' do
14
+ expect(validate({ string: 'foo' }, validations).valid?).to eq true
15
+ end
16
+
17
+ it 'should validate false when the value is not foo' do
18
+ expect(validate({ string: 'bar' }, validations).valid?).to eq false
19
+ expect(validate({ string: ' foo' }, validations).valid?).to eq false
20
+ expect(validate({ string: 'foo ' }, validations).valid?).to eq false
21
+ expect(validate({ string: nil }, validations).valid?).to eq false
22
+ expect(validate({ string: 0 }, validations).valid?).to eq false
23
+ expect(validate({ string: true }, validations).valid?).to eq false
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-04 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,6 +96,7 @@ files:
96
96
  - lib/hash_validator/validators/many_validator.rb
97
97
  - lib/hash_validator/validators/optional_validator.rb
98
98
  - lib/hash_validator/validators/presence_validator.rb
99
+ - lib/hash_validator/validators/regex_validator.rb
99
100
  - lib/hash_validator/validators/simple_type_validators.rb
100
101
  - lib/hash_validator/validators/simple_validator.rb
101
102
  - lib/hash_validator/version.rb
@@ -110,6 +111,7 @@ files:
110
111
  - spec/validators/many_spec.rb
111
112
  - spec/validators/optional_spec.rb
112
113
  - spec/validators/presence_spec.rb
114
+ - spec/validators/regexp_spec.rb
113
115
  - spec/validators/simple_spec.rb
114
116
  - spec/validators/simple_types_spec.rb
115
117
  - spec/validators/user_defined_spec.rb
@@ -149,6 +151,7 @@ test_files:
149
151
  - spec/validators/many_spec.rb
150
152
  - spec/validators/optional_spec.rb
151
153
  - spec/validators/presence_spec.rb
154
+ - spec/validators/regexp_spec.rb
152
155
  - spec/validators/simple_spec.rb
153
156
  - spec/validators/simple_types_spec.rb
154
157
  - spec/validators/user_defined_spec.rb