sanatio 0.4.0 → 0.5.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: bd128dbe87fa8e5eedada9ea84cd2c2ecaa1fbf0
4
- data.tar.gz: 12d18969cdb230afa2c0a7f69d2232261ba7c253
3
+ metadata.gz: 86489fb3a7e95291f3cb895dd5ad7b46e6469501
4
+ data.tar.gz: 02a12e955cb9f32e3375610da45d4d2ab275a03d
5
5
  SHA512:
6
- metadata.gz: 934d064743bdd8381f0d950757867d1bf015062a113dfe7b855901a36ffdffc275c445960101f351aa79bd93209dd323521d46a6474aecc7896cc564ace2ab0a
7
- data.tar.gz: 1593525b215691eafce260a7be7c966ad8ec346661b72ffac86d714b6bc62151b54bedc0371f3397b8f9e04a209a01ef0c6f9fe7e7148768bc8f9486b432c771
6
+ metadata.gz: e9a414ffd1a40f35cc81e9443258defd54156a22ec5e002e049da71d23f15bf03d54694940664440e4484d8dd455423f955afd69a660c783db8362e9c24b4783
7
+ data.tar.gz: 83bade7aa04d63bbfb66ca0d5c7bc0f369ba0b91bfe8cbf5d55778cbb0762a6710dd1a7c0c8c441a8883797c09c0c01a4e556e0a107bba612a84b5cb99c95189
data/README.md CHANGED
@@ -207,6 +207,50 @@ Person.new(15).valid? #true
207
207
  Person.new(19).valid? #false
208
208
  ```
209
209
 
210
+ #### EqualTo
211
+
212
+ This validation fails when the field is not equal to the given value.
213
+
214
+ ```ruby
215
+ class Person
216
+ include Sanatio
217
+
218
+ def initialize(age)
219
+ @age = age
220
+ end
221
+
222
+ attr_reader :age
223
+
224
+ ensure_that(:age).is EqualTo, 18
225
+ endO
226
+
227
+ Person.new(nil).valid? #false
228
+ Person.new(15).valid? #false
229
+ Person.new(18).valid? #true
230
+ ```
231
+
232
+ #### NotEqualTo
233
+
234
+ This validation fails when the field is equal to the given value.
235
+
236
+ ```ruby
237
+ class Person
238
+ include Sanatio
239
+
240
+ def initialize(age)
241
+ @age = age
242
+ end
243
+
244
+ attr_reader :age
245
+
246
+ ensure_that(:age).is NotEqualTo, 18
247
+ endO
248
+
249
+ Person.new(nil).valid? #true
250
+ Person.new(15).valid? #true
251
+ Person.new(18).valid? #false
252
+ ```
253
+
210
254
  #### OneOf
211
255
 
212
256
  This validation fails when the value is not in the list given.
@@ -295,7 +339,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
295
339
 
296
340
  ## Contributing
297
341
 
298
- 1. Fork it ( https://github.com/[my-github-username]/sanatio/fork )
342
+ 1. Fork it ( https://github.com/ThijsWouters/sanatio/fork )
299
343
  2. Create your feature branch (`git checkout -b my-new-feature`)
300
344
  3. Commit your changes (`git commit -am 'Add some feature'`)
301
345
  4. Push to the branch (`git push origin my-new-feature`)
@@ -0,0 +1,20 @@
1
+ class EqualTo
2
+ def initialize(value)
3
+ @value = value
4
+ end
5
+
6
+ def skip?(object)
7
+ end
8
+
9
+ def valid?(object)
10
+ object == @value
11
+ end
12
+
13
+ def reason
14
+ :not_equal_to
15
+ end
16
+
17
+ def params
18
+ [@value]
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ class NotEqualTo
2
+ def initialize(value)
3
+ @value = value
4
+ end
5
+
6
+ def skip?(object)
7
+ end
8
+
9
+ def valid?(object)
10
+ object != @value
11
+ end
12
+
13
+ def reason
14
+ :equal_to
15
+ end
16
+
17
+ def params
18
+ [@value]
19
+ end
20
+ end
@@ -3,6 +3,8 @@ require 'sanatio/built-in/greater_than_or_equal_to'
3
3
  require 'sanatio/built-in/greater_than'
4
4
  require 'sanatio/built-in/less_than_or_equal_to'
5
5
  require 'sanatio/built-in/less_than'
6
+ require 'sanatio/built-in/equal_to'
7
+ require 'sanatio/built-in/not_equal_to'
6
8
  require 'sanatio/built-in/one_of'
7
9
  require 'sanatio/built-in/valid'
8
10
  require 'sanatio/built-in/matching'
@@ -1,3 +1,3 @@
1
1
  module Sanatio
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanatio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Wouters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,11 +72,13 @@ files:
72
72
  - lib/sanatio.rb
73
73
  - lib/sanatio/block_validator.rb
74
74
  - lib/sanatio/built-in.rb
75
+ - lib/sanatio/built-in/equal_to.rb
75
76
  - lib/sanatio/built-in/greater_than.rb
76
77
  - lib/sanatio/built-in/greater_than_or_equal_to.rb
77
78
  - lib/sanatio/built-in/less_than.rb
78
79
  - lib/sanatio/built-in/less_than_or_equal_to.rb
79
80
  - lib/sanatio/built-in/matching.rb
81
+ - lib/sanatio/built-in/not_equal_to.rb
80
82
  - lib/sanatio/built-in/one_of.rb
81
83
  - lib/sanatio/built-in/present.rb
82
84
  - lib/sanatio/built-in/support/compare.rb