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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 083c986d0c9f200a3780b92590eba1a6c5a3bc19
4
- data.tar.gz: f43f7f87b611a0b448e7e5962bf75c1cbe015d86
3
+ metadata.gz: f8817e1d2d70600656f15f6900ca222ac4366148
4
+ data.tar.gz: c6471f2710dd9828e165aa9d79c3108d1bcb7d1a
5
5
  SHA512:
6
- metadata.gz: 3410c9606685bd160689050acb9bc1826ccab7931eeb5db74f5da1bb6d426b2cb001b53453579d2b7a6f6c6b7381f258fef60347a981a704459505fe4d66a1c4
7
- data.tar.gz: 8b43927c3a5ad3d8e6676f00b44b05103265016e7a11ade494359f55e2f157cea72ee9091010f9933c20225945f6470493994fede79599f6969e9b2a2d97d450
6
+ metadata.gz: 92d733d81cb224610afe5f74095df9ce27fba5f443d0a71155fb60b118ede6fabe2b79f0175954e75a6d07a3eee959d42b7cd7e2e2713494ff0605b6d6ff602a
7
+ data.tar.gz: d091a42649987feb5eef9520256e6bf7c74dc44ef86b4ad434e16e3899371b07976d39f3e130f1c076d6cf88f0027263fb2d47fda40e6513a9d04f736f417680
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg/
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
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
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
- s.files = [
14
- "README",
15
- "TODO",
16
- "hashidator.gemspec",
17
- "lib/hashidator.rb",
18
- "lib/hashidator/version.rb"
19
- ]
20
- s.test_files = [
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
@@ -1,3 +1,3 @@
1
1
  class Hashidator
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/test/helper.rb CHANGED
@@ -1,9 +1,7 @@
1
- $:.unshift "lib"
2
-
3
- require 'test/unit'
1
+ require 'minitest/autorun'
4
2
  require 'hashidator'
5
3
 
6
- class Test::Unit::TestCase
4
+ class Minitest::Test
7
5
  def assert_true(subject)
8
6
  assert_equal true, subject
9
7
  end
@@ -1,6 +1,6 @@
1
- require './test/helper.rb'
1
+ require 'helper'
2
2
 
3
- class TestHashidator < Test::Unit::TestCase
3
+ class TestHashidator < Minitest::Test
4
4
  def h(schema, input)
5
5
  Hashidator.validate(schema, input)
6
6
  end
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.0
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: []