yas 0.2.2 → 0.2.3

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: d2d1f54023a01907f599f48cca90bb9242a62089
4
- data.tar.gz: 07c833f91eea25fcd26c65d07e2aa841a112e8a0
3
+ metadata.gz: f3a9193b509349e971261e201331016667604f25
4
+ data.tar.gz: 4844084a1e9daf9827a35d09d7eedba99c94e783
5
5
  SHA512:
6
- metadata.gz: 55eb0916f52e24c460bb6052694375ffb916f1428b3a700fca8d9c2ed98cf531818b2f2c8ad0638ddd81d41656b2ffe0bf6a46e209d45ee639747b66b1f255d0
7
- data.tar.gz: 45f84dab4db77099310d49bf9236c4ee622bb6f98b113b53d7de1c2b17ad9b7d9f3b264cb25438f0026d6715d7d07f937bdf8c2667aead73f94b54d62a0f9e1d
6
+ metadata.gz: b9e32b743473ebee080449f11bcaaa6c167341254c8ad74913122650c22bed36b6526e1a21d121951e5dc3d4711bef69a69925e81ec23fe97c8c4649df010acb
7
+ data.tar.gz: 53ed8cb19ffa22459ffde074c47cdec1befb6369157464ae81bcb5cce1f601ee8886c9773ef19e427e8c42008799ad92b273127beecc0fc0c3617a316a6900ee
@@ -5,11 +5,12 @@ class YAS::AttributeExt
5
5
 
6
6
  module ClassMethods
7
7
 
8
- def key attr, &block
9
- new_attr = Attribute.new(attr)
10
- new_attr.instance_eval &block if block
11
- attributes[attr] = new_attr
12
- new_attr
8
+ def key *attrs, &block
9
+ attrs.each do |attr|
10
+ new_attr = Attribute.new(attr)
11
+ new_attr.instance_eval(&block) if block
12
+ attributes[attr] = new_attr
13
+ end
13
14
  end
14
15
  alias_method :attribute, :key
15
16
 
@@ -45,15 +46,14 @@ class YAS::AttributeExt
45
46
 
46
47
  attr_reader :name
47
48
 
48
- @required = false
49
- @type = nil
50
- @auto_convert = false
51
- @default_block = nil
52
- @alter_block = nil
53
- @validate_value_block = nil
54
-
55
49
 
56
50
  def initialize name
51
+ @required = false
52
+ @type = nil
53
+ @auto_convert = false
54
+ @default_block = nil
55
+ @alter_block = nil
56
+ @validate_value_block = nil
57
57
  @name = name
58
58
  end
59
59
 
@@ -5,7 +5,7 @@ class YAS::SymbolizeExt
5
5
 
6
6
  module ClassMethods
7
7
  def symbolize sym = nil
8
- @symbolize = sym if !sym.nil? && (sym.class == TrueClass || sym.class == FalseClass)
8
+ (!sym.nil? && (sym.class == TrueClass || sym.class == FalseClass)) ? @symbolize = sym : @symbolize = nil
9
9
  @symbolize
10
10
  end
11
11
  end
data/lib/yas/hash.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Hash
2
2
 
3
3
  def validate schema
4
- copy = Marshal.load(Marshal.dump(self))
4
+ copy = Hash[self]
5
5
  schema.validate(copy) if schema.respond_to?(:validate)
6
6
  end
7
7
 
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.2"
4
+ VERSION = "0.2.3"
5
5
  end
@@ -121,9 +121,11 @@ class TestAttribute < Minitest::Test
121
121
 
122
122
  def test_validate_maintain_value_if_type_not_specified
123
123
  attr = Attribute.new(:batman)
124
- [true, false, :symbol, 1, 0, -1, 10.0, "string", 1293.1, 0x90, Time.now, nil].each do |v|
124
+ [true, false, :symbol, 1, 0, -1, 10.0, "string", 1293.1, 0x90, Time.now].each do |v|
125
125
  assert_equal v, attr.validate(v)
126
126
  end
127
+
128
+ assert_nil attr.validate(nil)
127
129
  end
128
130
 
129
131
  end
@@ -163,6 +165,16 @@ class NestedAttributeSchema < YAS::Schema
163
165
  end
164
166
 
165
167
 
168
+ class MultipleAttributesSchema < YAS::Schema
169
+
170
+ key :personal_info, "other_info" do
171
+ required
172
+ type String
173
+ end
174
+
175
+ end
176
+
177
+
166
178
  class TestAttributeExt < Minitest::Test
167
179
 
168
180
  def test_attribute_ext
@@ -211,4 +223,14 @@ class TestAttributeExt < Minitest::Test
211
223
  assert_equal "joe", hash[:personal_info][:name]
212
224
  end
213
225
 
226
+ def test_multiple_attributes_with_same_block
227
+ hash = {
228
+ personal_info: "when",
229
+ "other_info" => "who"
230
+ }
231
+ hash.validate! MultipleAttributesSchema
232
+ assert_equal "when", hash[:personal_info]
233
+ assert_equal "who", hash["other_info"]
234
+ end
235
+
214
236
  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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -101,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 2.5.2
104
+ rubygems_version: 2.6.4
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Yet Another Schema for Ruby.
108
108
  test_files: []
109
- has_rdoc: