yas 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/yas/ext/attribute.rb +12 -12
- data/lib/yas/ext/symbolize.rb +1 -1
- data/lib/yas/hash.rb +1 -1
- data/lib/yas/version.rb +1 -1
- data/test/ext/test_attribute.rb +23 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a9193b509349e971261e201331016667604f25
|
4
|
+
data.tar.gz: 4844084a1e9daf9827a35d09d7eedba99c94e783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e32b743473ebee080449f11bcaaa6c167341254c8ad74913122650c22bed36b6526e1a21d121951e5dc3d4711bef69a69925e81ec23fe97c8c4649df010acb
|
7
|
+
data.tar.gz: 53ed8cb19ffa22459ffde074c47cdec1befb6369157464ae81bcb5cce1f601ee8886c9773ef19e427e8c42008799ad92b273127beecc0fc0c3617a316a6900ee
|
data/lib/yas/ext/attribute.rb
CHANGED
@@ -5,11 +5,12 @@ class YAS::AttributeExt
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
|
8
|
-
def key
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
|
data/lib/yas/ext/symbolize.rb
CHANGED
@@ -5,7 +5,7 @@ class YAS::SymbolizeExt
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def symbolize sym = nil
|
8
|
-
|
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
data/lib/yas/version.rb
CHANGED
data/test/ext/test_attribute.rb
CHANGED
@@ -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
|
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.
|
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:
|
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.
|
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:
|