typed 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/typed/schema.rb +6 -1
- data/lib/typed/version.rb +1 -1
- data/spec/conversion_spec.rb +27 -0
- metadata +5 -4
data/lib/typed/schema.rb
CHANGED
@@ -78,7 +78,7 @@ module Typed
|
|
78
78
|
return true unless klass
|
79
79
|
# raise Schema::NotFound, key.to_s unless klass
|
80
80
|
|
81
|
-
if
|
81
|
+
if struct?(val, klass)
|
82
82
|
return true
|
83
83
|
else
|
84
84
|
expected = klass.inspect
|
@@ -89,6 +89,11 @@ module Typed
|
|
89
89
|
end
|
90
90
|
|
91
91
|
private
|
92
|
+
def struct?(val, klass)
|
93
|
+
return true if klass == Object
|
94
|
+
return val.must.struct?(klass)
|
95
|
+
end
|
96
|
+
|
92
97
|
def implicit(key, val)
|
93
98
|
val = Implicit.new(val) unless val.is_a?(Implicit)
|
94
99
|
@types[key.to_s] = val
|
data/lib/typed/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Typed::Hash do
|
4
|
+
def data
|
5
|
+
subject
|
6
|
+
end
|
7
|
+
|
8
|
+
context "(Object schema)" do
|
9
|
+
it "should accept []" do
|
10
|
+
data["a"] = Object
|
11
|
+
lambda {
|
12
|
+
data["a"] = []
|
13
|
+
}.should_not raise_error
|
14
|
+
data["a"].should == []
|
15
|
+
data.schema("a").should == Object
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept ['x']" do
|
19
|
+
data["a"] = Object
|
20
|
+
lambda {
|
21
|
+
data["a"] = ['x']
|
22
|
+
}.should_not raise_error
|
23
|
+
data["a"].should == ['x']
|
24
|
+
data.schema("a").should == Object
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- maiha
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-07 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/typed/schema.rb
|
85
85
|
- lib/typed/version.rb
|
86
86
|
- spec/changes_spec.rb
|
87
|
+
- spec/conversion_spec.rb
|
87
88
|
- spec/default_spec.rb
|
88
89
|
- spec/events_spec.rb
|
89
90
|
- spec/hash_spec.rb
|