at-validations 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ The Azure License
2
+
3
+ Copyright (c) 2012 Kenneth Ballenegger
4
+
5
+ Attribute to Kenneth Ballenegger - kswizz.com
6
+
7
+ You (the licensee) are hereby granted permission, free of charge,
8
+ to deal in this software or source code (this "Software") without
9
+ restriction, including without limitation the rights to use, copy,
10
+ modify, merge, publish, distribute, and/or sublicense this
11
+ Software, subject to the following conditions:
12
+
13
+ You must give attribution to the party mentioned above, by name and
14
+ by hyperlink, in the about box, credits document and/or
15
+ documentation of any derivative work using a substantial portion of
16
+ this Software.
17
+
18
+ You may not use the name of the copyright holder(s) to endorse or
19
+ promote products derived from this Software without specific prior
20
+ written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28
+ CONNECTION WITH THIS SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS
29
+ SOFTWARE.
30
+
31
+ http://license.azuretalon.com/
@@ -7,7 +7,9 @@ require File.expand_path("#{File.dirname(__FILE__)}/at-validations/version.rb")
7
7
  #
8
8
  # {hello: :world}.matches_mask({
9
9
  # _id: atv_string,
10
- # status: atv_number + atv_block {|e| e >= 200 && e < 300 }
10
+ # status: atv_union(
11
+ # atv_number,
12
+ # atv_block {|e| e >= 200 && e < 300 })
11
13
  # })
12
14
  #
13
15
 
@@ -17,6 +19,12 @@ class Hash
17
19
  end
18
20
  end
19
21
 
22
+ class Object
23
+ def matches_predicate(predicate)
24
+ predicate.call(self)
25
+ end
26
+ end
27
+
20
28
 
21
29
  module ATValidations
22
30
 
@@ -48,7 +56,7 @@ module ATValidations
48
56
  atv_instance_of(Array),
49
57
  atv_block do |e|
50
58
  errs = {}
51
- e.each_index {|i| errs[i] = err unless true == (err = predicate.call(e)) }
59
+ e.each_index {|i| err = predicate.call(e); errs[i] = err unless true == err }
52
60
  errs.count == 0 || Error.new(:error => 'array contains elements which do not match predicate', :failures => errs)
53
61
  end
54
62
  )
@@ -99,6 +107,12 @@ module ATValidations
99
107
  def atv_symbol
100
108
  atv_instance_of(Symbol)
101
109
  end
110
+
111
+ def atv_nil_or(predicate)
112
+ atv_block do |e|
113
+ nil == e || predicate.call(e)
114
+ end
115
+ end
102
116
  end
103
117
 
104
118
  class Error < StandardError
@@ -1,3 +1,3 @@
1
1
  module ATValidations
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: at-validations
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Awesome validation and object matching library
15
15
  email:
@@ -20,7 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
22
  - Gemfile
23
- - LICENSE.txt
23
+ - LICENSE.md
24
24
  - README.md
25
25
  - Rakefile
26
26
  - at-validations.gemspec
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Kenneth Ballenegger
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.