schash 0.1.1 → 0.1.2

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: c6e7d207a677b2b5941b9bf2f59d43fe38ee74c7
4
- data.tar.gz: 9497b992bd3ea937fd11cfe3a35caf788f3951b3
3
+ metadata.gz: d901ec92f618c3919a2ef43bc53004cc28a7335f
4
+ data.tar.gz: 6abf7b2d0812c77fe311433573b652f615450723
5
5
  SHA512:
6
- metadata.gz: 0e69aaef9fc52845432e6ab0577577b7f48205d88e0861c17babf5bd1f4999a0b4617b9b313b2f428236c29542ac534f04937c17e6bbbd99c9ed2d819d2ea5ae
7
- data.tar.gz: 40cdb442104335f83cec9597ceda90339bc6d3f0eaf93f3be6036883ccdbd6aa5082583553d7c6889aca12890e742c044158a07825144d25b2567a33221f4d18
6
+ metadata.gz: 10de3bff54d71bd105277f85b6ad75de308d3003cefcf2ff99301b5631cada6c0ca775abba7ca4e35fa38c7e03335c095be51e8cea7b43d8bb4e599a3874fcba
7
+ data.tar.gz: d82d77a14a7f9525ca9e7947936450d817ce6807fb18b7f08ff1e31d322ad4a07c884ae412fcfb4bc82d102c915ca89cdcc879ddae437c9f416f43c5ced617ae
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # Schash
1
+ # Schash [![Build Status](https://travis-ci.org/ryotarai/schash.svg?branch=master)](https://travis-ci.org/ryotarai/schash)
2
2
 
3
3
  Pronounciation: the same as "squash"
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/schash`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
5
+ Ruby hash validator
8
6
 
9
7
  ## Installation
10
8
 
@@ -31,6 +29,7 @@ validator = Schash::Validator.new do
31
29
  root: string,
32
30
  allowed_ips: array_of(string),
33
31
  }),
32
+ listen: match(/^(80|443)$/),
34
33
  },
35
34
  }
36
35
  end
@@ -45,6 +44,7 @@ valid = {
45
44
  root: "/var/www/itamae",
46
45
  allowed_ips: ["127.0.0.1/32"],
47
46
  }],
47
+ listen: "80"
48
48
  },
49
49
  }
50
50
 
@@ -59,11 +59,12 @@ invalid = {
59
59
  root: "/var/www/itamae",
60
60
  allowed_ips: ["127.0.0.1/32"],
61
61
  },
62
+ listen: "8080"
62
63
  },
63
64
  }
64
65
 
65
66
  validator.validate(invalid)
66
- # => [#<struct Schash::Schema::Error position=["nginx", "user"], message="is not String">, #<struct Schash::Schema::Error position=["nginx", "sites"], message="is not an array">]
67
+ # => [#<struct Schash::Schema::Error position=["nginx", "user"], message="is not String">, #<struct Schash::Schema::Error position=["nginx", "sites"], message="is not an array">, #<struct Schash::Schema::Error position=["nginx", "listen"], message="does not match /^(80|443)$/">]
67
68
  ```
68
69
 
69
70
  ## Development
@@ -74,7 +75,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
74
75
 
75
76
  ## Contributing
76
77
 
77
- 1. Fork it ( https://github.com/[my-github-username]/schash/fork )
78
+ 1. Fork it ( https://github.com/ryotarai/schash/fork )
78
79
  2. Create your feature branch (`git checkout -b my-new-feature`)
79
80
  3. Commit your changes (`git commit -am 'Add some feature'`)
80
81
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ rescue LoadError
6
+ end
2
7
 
8
+ task :default => :spec
@@ -48,6 +48,10 @@ module Schash
48
48
  def boolean
49
49
  one_of_types(TrueClass, FalseClass)
50
50
  end
51
+
52
+ def match(pattern)
53
+ Rule::Match.new(pattern)
54
+ end
51
55
  end
52
56
  end
53
57
  end
@@ -4,4 +4,5 @@ require 'schash/schema/rule/one_of_types'
4
4
  require 'schash/schema/rule/hash'
5
5
  require 'schash/schema/rule/optional'
6
6
  require 'schash/schema/rule/type'
7
+ require 'schash/schema/rule/match'
7
8
 
@@ -0,0 +1,21 @@
1
+ module Schash
2
+ module Schema
3
+ module Rule
4
+ class Match < Base
5
+ def initialize(pattern)
6
+ @pattern = pattern
7
+ end
8
+
9
+ def validate(target, position = [])
10
+ errors = []
11
+
12
+ unless @pattern.match(target)
13
+ errors << Error.new(position, "does not match #{@pattern.inspect}")
14
+ end
15
+
16
+ errors
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Schash
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - lib/schash/schema/rule/array_of.rb
77
77
  - lib/schash/schema/rule/base.rb
78
78
  - lib/schash/schema/rule/hash.rb
79
+ - lib/schash/schema/rule/match.rb
79
80
  - lib/schash/schema/rule/one_of_types.rb
80
81
  - lib/schash/schema/rule/optional.rb
81
82
  - lib/schash/schema/rule/type.rb