yas 0.2.3 → 0.2.4

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: f3a9193b509349e971261e201331016667604f25
4
- data.tar.gz: 4844084a1e9daf9827a35d09d7eedba99c94e783
3
+ metadata.gz: 8e8d3f4d4fa15965f7f65e3175a6ba8e395f0010
4
+ data.tar.gz: 4e29b1b399957476619629514759ab78496505d9
5
5
  SHA512:
6
- metadata.gz: b9e32b743473ebee080449f11bcaaa6c167341254c8ad74913122650c22bed36b6526e1a21d121951e5dc3d4711bef69a69925e81ec23fe97c8c4649df010acb
7
- data.tar.gz: 53ed8cb19ffa22459ffde074c47cdec1befb6369157464ae81bcb5cce1f601ee8886c9773ef19e427e8c42008799ad92b273127beecc0fc0c3617a316a6900ee
6
+ metadata.gz: 946ccc4ee9e06eee567e090a568a5d80c3f0720209697d961a389bf18a9995a292159c59b5ff3c534e7726e52508df35477447d7b2aa51331b949c37622dd3f3
7
+ data.tar.gz: 67a80c808a9c388b21b9e9a9e2fd26a9b865863da67c5a419b6bbd25c4fab6c56b5df332a212b8962c02ddcba75b33347caf9178c966fdc5e2912342e00cf163
data/README.markdown CHANGED
@@ -7,9 +7,10 @@ Using YAS, you can enforce a specific key to be required, rename them, perform a
7
7
  ## Installation
8
8
 
9
9
  gem install yas
10
+ require 'yas'
10
11
 
11
12
 
12
- ## Quick Start
13
+ ## Quick Example
13
14
 
14
15
  require 'yas'
15
16
 
@@ -37,6 +38,7 @@ Optionally, you may also use `YAS::SchemaBase` if you want to start off from a c
37
38
 
38
39
  Declares an attribute/key with various requirements.
39
40
  The Attribute extension allows you to specify certain requirements/restrictions for a given key.
41
+ `attribute` and `key` are aliases, you can use either one.
40
42
 
41
43
  attribute name, &block
42
44
  key name, &block
@@ -58,6 +60,15 @@ Example:
58
60
  hash.merge!(:email => 'john@email.com')
59
61
  hash.validate! MySchema # Success!
60
62
 
63
+ You can also specify multiple keys per `key`/`attribute` block.
64
+
65
+ class MySchema < YAS::Schema
66
+ attribute :email, :first_name do
67
+ required
68
+ type String
69
+ end
70
+ end
71
+
61
72
  List of directives you can use:
62
73
 
63
74
  * `required`
@@ -143,7 +154,7 @@ Example:
143
154
  #### Symbolize
144
155
 
145
156
  Symbolize keys in your hash.
146
- This does not perform deep symbolize. See nested Attribute validation if you want deep symbolize.
157
+ This does not perform deep symbolize. See `type` in the Attribute section for if you want deep symbolize.
147
158
 
148
159
  symbolize true|false
149
160
 
@@ -5,7 +5,8 @@ class YAS::SymbolizeExt
5
5
 
6
6
  module ClassMethods
7
7
  def symbolize sym = nil
8
- (!sym.nil? && (sym.class == TrueClass || sym.class == FalseClass)) ? @symbolize = sym : @symbolize = nil
8
+ @symbolize = sym if (!sym.nil? && (sym.class == TrueClass || sym.class == FalseClass))
9
+ @symbolize = false unless defined? @symbolize
9
10
  @symbolize
10
11
  end
11
12
  end
data/lib/yas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YAS
2
2
  GEM_NAME = "yas"
3
3
  NAME = "YAS"
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
@@ -231,6 +231,13 @@ class TestAttributeExt < Minitest::Test
231
231
  hash.validate! MultipleAttributesSchema
232
232
  assert_equal "when", hash[:personal_info]
233
233
  assert_equal "who", hash["other_info"]
234
+
235
+ hash = {
236
+ personal_info: "when",
237
+ }
238
+ assert_raises YAS::ValidationError do
239
+ hash.validate! MultipleAttributesSchema
240
+ end
234
241
  end
235
242
 
236
243
  end
@@ -5,13 +5,20 @@ class SymbolizedSchema < YAS::Schema
5
5
  symbolize true
6
6
  end
7
7
 
8
+ class NotSymbolizedSchema < YAS::Schema
9
+ attribute :first_name do
10
+ required
11
+ type String
12
+ end
13
+ end
14
+
8
15
 
9
16
  class TestSymbolizeExt < Minitest::Test
10
17
 
11
18
  def test_symbolize
12
19
  hash = {
13
- 'first_name': "john",
14
- 'last_name': "doe",
20
+ 'first_name' => "john",
21
+ 'last_name' => "doe",
15
22
  }
16
23
  hash.validate! SymbolizedSchema
17
24
  assert_equal "john", hash[:first_name]
@@ -20,4 +27,13 @@ class TestSymbolizeExt < Minitest::Test
20
27
  assert_nil hash['last_name']
21
28
  end
22
29
 
30
+ def test_not_symbolize
31
+ hash = {
32
+ 'first_name' => "john",
33
+ }
34
+ assert_raises YAS::ValidationError do
35
+ hash.validate! NotSymbolizedSchema
36
+ end
37
+ end
38
+
23
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest