hashidator 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGES +56 -0
- data/Gemfile +3 -0
- data/README +6 -0
- data/Rakefile +13 -0
- data/examples/basic.rb +81 -0
- data/hashidator.gemspec +8 -11
- data/lib/hashidator/version.rb +1 -1
- data/test/helper.rb +2 -4
- data/test/test_hashidator.rb +2 -2
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8817e1d2d70600656f15f6900ca222ac4366148
|
4
|
+
data.tar.gz: c6471f2710dd9828e165aa9d79c3108d1bcb7d1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92d733d81cb224610afe5f74095df9ce27fba5f443d0a71155fb60b118ede6fabe2b79f0175954e75a6d07a3eee959d42b7cd7e2e2713494ff0605b6d6ff602a
|
7
|
+
data.tar.gz: d091a42649987feb5eef9520256e6bf7c74dc44ef86b4ad434e16e3899371b07976d39f3e130f1c076d6cf88f0027263fb2d47fda40e6513a9d04f736f417680
|
data/.gitignore
ADDED
data/CHANGES
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= 0.4.1 / 2016-03-07
|
2
|
+
|
3
|
+
* Modernize project (bundler, minitest). [Peter Suschlik]
|
4
|
+
|
5
|
+
= 0.4.0 / 2011-06-07
|
6
|
+
|
7
|
+
* Note: This was pushed to rubygems on 2016-03-07
|
8
|
+
|
9
|
+
* Better support for subclassing Hashidator. [Peter Suschlik]
|
10
|
+
|
11
|
+
* Custom validator classes need to implement #===. [Peter Suschlik]
|
12
|
+
|
13
|
+
Optional value example:
|
14
|
+
|
15
|
+
class OpionalValue
|
16
|
+
def initialize(schema)
|
17
|
+
@schema = schema
|
18
|
+
end
|
19
|
+
|
20
|
+
def ===(value)
|
21
|
+
value.nil? || @schema
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
schema = Hashidator.new(:name => String, :hobby => OpionalValue.new(String))
|
26
|
+
schema.validate(:name => "Bob", :hobby => "Cipher") # => true
|
27
|
+
schema.validate(:name => "Bob") # => true, even without a hobby
|
28
|
+
schema.validate(:name => "Bob", :hobby => 23) # => falseo
|
29
|
+
|
30
|
+
* Add string validator [Peter Suschlik]
|
31
|
+
|
32
|
+
= 0.3.1 / 2010-10-05
|
33
|
+
|
34
|
+
* Bug fix: Failing on nil as input [Peter Suschlik]
|
35
|
+
* Bug fix: Failing on non-array input to array schema [Peter Suschlik]
|
36
|
+
|
37
|
+
= 0.3 / 2010-02-03
|
38
|
+
|
39
|
+
* Validate with procs. [Peter Suschlik]
|
40
|
+
|
41
|
+
Proc returns a boolean or another validator.
|
42
|
+
Now you can write custom validators like:
|
43
|
+
|
44
|
+
schema = Hashidator.new(:ary => proc {|v| v.size == 3 })
|
45
|
+
schema.validate(:ary => [1,2,3]) # => true
|
46
|
+
schema.validate(:ary => [1,2]) # => false
|
47
|
+
|
48
|
+
= 0.2 / 2009-12-19
|
49
|
+
|
50
|
+
* Validate regexp: :foo => /match this/
|
51
|
+
|
52
|
+
* Validate hashes in arrays: [{:foo => String}] [Peter Suschlik]
|
53
|
+
|
54
|
+
= 0.1 / 2009-12-18
|
55
|
+
|
56
|
+
* Release 0.1
|
data/Gemfile
ADDED
data/README
CHANGED
@@ -13,6 +13,12 @@ define schemas as a hash, and validate hashes!
|
|
13
13
|
see examples/basic.rb for full coverage. it knows
|
14
14
|
classes, ranges, booleans, proc and duck typing. yay!
|
15
15
|
|
16
|
+
to release this gem:
|
17
|
+
* edit lib/hashidator/version.rb
|
18
|
+
* edit CHANGES
|
19
|
+
* git commit -am "Release VERSION"
|
20
|
+
* rake release
|
21
|
+
|
16
22
|
(c) 2009 harry vangberg <harry@vangberg.name>,
|
17
23
|
peter suschlik <peter@suschlik.de>
|
18
24
|
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task :default => :test
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
Rake::TestTask.new(:test) do |test|
|
10
|
+
test.test_files = FileList.new('test/**/test_*.rb')
|
11
|
+
test.libs << 'test'
|
12
|
+
test.verbose = true
|
13
|
+
end
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'hashidator'
|
2
|
+
|
3
|
+
class OptionalValue
|
4
|
+
def initialize(schema)
|
5
|
+
@schema = schema
|
6
|
+
end
|
7
|
+
|
8
|
+
def ===(value)
|
9
|
+
value.nil? || @schema
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
schema = {
|
14
|
+
:id => Integer, # Is integer?
|
15
|
+
:name => String,
|
16
|
+
:age => (13..99), # Within range?
|
17
|
+
:admin => Boolean,
|
18
|
+
:mails => [String], # Array consisting of strings?
|
19
|
+
:other => {
|
20
|
+
:country_code => :to_i, # Ducktyping!
|
21
|
+
:country => String,
|
22
|
+
:random => /foo/ # Regular expressions
|
23
|
+
},
|
24
|
+
:result => "ok",
|
25
|
+
:bool => true,
|
26
|
+
:hotchicks => OptionalValue.new([{ :name => String, :age => (18..30) }]),
|
27
|
+
:validate_array => [{:name => String}],
|
28
|
+
:validate_array_size => proc {|v| v.size == 3 }
|
29
|
+
}
|
30
|
+
|
31
|
+
valid_input = {
|
32
|
+
:id => 123,
|
33
|
+
:name => "Harry",
|
34
|
+
:age => 21,
|
35
|
+
:admin => true,
|
36
|
+
:mails => ["foo@example.com", "bar@example.com"],
|
37
|
+
:other => {
|
38
|
+
:country => "Denmark",
|
39
|
+
:country_code => 12,
|
40
|
+
:random => "foobar"
|
41
|
+
},
|
42
|
+
:result => "ok",
|
43
|
+
:bool => true,
|
44
|
+
:hotchicks => [
|
45
|
+
{ :name => "Nura", :age => 26 },
|
46
|
+
{ :name => "Sarah", :age => 30 }
|
47
|
+
],
|
48
|
+
:validate_array => [
|
49
|
+
{:name => "John"},
|
50
|
+
{:name => "Coltrane"}
|
51
|
+
],
|
52
|
+
:validate_array_size => [1,2,3]
|
53
|
+
}
|
54
|
+
|
55
|
+
invalid_input = {
|
56
|
+
:id => "whatevz",
|
57
|
+
:name => 42,
|
58
|
+
:age => 12,
|
59
|
+
:admin => :maybe,
|
60
|
+
:mails => ["foo@example.com", 1234],
|
61
|
+
:other => {
|
62
|
+
:country => [1,2,3],
|
63
|
+
:country_code => (1..2),
|
64
|
+
:random => "nothing here"
|
65
|
+
},
|
66
|
+
:result => "error",
|
67
|
+
:bool => false,
|
68
|
+
:hotchicks => [
|
69
|
+
{ :name => "Uma", :age => 42 }
|
70
|
+
],
|
71
|
+
:validate_array => [
|
72
|
+
{:name => "John"},
|
73
|
+
{:name => 1234}
|
74
|
+
],
|
75
|
+
:validate_array_size => [1,2]
|
76
|
+
}
|
77
|
+
|
78
|
+
h = Hashidator.new(schema)
|
79
|
+
puts h.validate(valid_input) #=> true
|
80
|
+
puts "=" * 80
|
81
|
+
puts h.validate(invalid_input) #=> false
|
data/hashidator.gemspec
CHANGED
@@ -10,15 +10,12 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = "define schemas as a hash, and validate hashes!"
|
11
11
|
s.has_rdoc = false
|
12
12
|
s.authors = ["Harry Vangberg", "Peter Suschlik"]
|
13
|
-
|
14
|
-
|
15
|
-
"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
s.
|
21
|
-
"test/helper.rb",
|
22
|
-
"test/test_hashidator.rb"
|
23
|
-
]
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake', '~> 10.5.0'
|
20
|
+
s.add_development_dependency 'minitest', '~> 5.8.4'
|
24
21
|
end
|
data/lib/hashidator/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_hashidator.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Vangberg
|
@@ -10,15 +10,48 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2016-03-07 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 10.5.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 10.5.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 5.8.4
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 5.8.4
|
14
42
|
description: define schemas as a hash, and validate hashes!
|
15
43
|
email: harry@vangberg.name
|
16
44
|
executables: []
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CHANGES
|
50
|
+
- Gemfile
|
20
51
|
- README
|
52
|
+
- Rakefile
|
21
53
|
- TODO
|
54
|
+
- examples/basic.rb
|
22
55
|
- hashidator.gemspec
|
23
56
|
- lib/hashidator.rb
|
24
57
|
- lib/hashidator/version.rb
|
@@ -47,7 +80,4 @@ rubygems_version: 2.5.1
|
|
47
80
|
signing_key:
|
48
81
|
specification_version: 4
|
49
82
|
summary: define schemas as a hash, and validate hashes!
|
50
|
-
test_files:
|
51
|
-
- test/helper.rb
|
52
|
-
- test/test_hashidator.rb
|
53
|
-
has_rdoc: false
|
83
|
+
test_files: []
|