typed 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/typed/hash.rb CHANGED
@@ -132,6 +132,10 @@ module Typed
132
132
  self[key].must.coerced(Time, Fixnum=>proc{|i| Time.at(i)})
133
133
  end
134
134
 
135
+ def utc(key)
136
+ Time.at(self[key].to_i).utc
137
+ end
138
+
135
139
  ######################################################################
136
140
  ### Utils
137
141
 
data/lib/typed/schema.rb CHANGED
@@ -52,11 +52,14 @@ module Typed
52
52
  when Explicit
53
53
  raise TypeError, "%s has already been declared as `%s'" % [key, @types[key.to_s].value.inspect]
54
54
  when Implicit
55
- # update schema if sub-class, otherwise raises
55
+ # update schema if same or sub-class, otherwise raises
56
+ declare.value == @types[key.to_s].value or # need this hack due to bug of Must#struct?
56
57
  declare.value.must.struct?(@types[key.to_s].value) or
57
58
  raise TypeError, "%s has already been typed as `%s'" % [key, @types[key.to_s].value.inspect]
59
+ explicit(key, declare)
60
+ else
61
+ explicit(key, declare)
58
62
  end
59
- explicit(key, declare)
60
63
 
61
64
  when Implicit
62
65
  case @types[key.to_s]
data/lib/typed/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typed
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/spec/hash_spec.rb CHANGED
@@ -129,6 +129,27 @@ describe Typed::Hash do
129
129
  }.should raise_error(TypeError)
130
130
  end
131
131
 
132
+ it "should accept atomic class (like Fixnum) for its schema" do
133
+ data[:foo] = 1
134
+ lambda {
135
+ data[:foo] = Fixnum
136
+ }.should_not raise_error
137
+ end
138
+
139
+ it "should accept complex classes (like [Fixnum]) for its schema" do
140
+ data[:foo] = [1]
141
+ lambda {
142
+ data[:foo] = [Fixnum]
143
+ }.should_not raise_error
144
+ end
145
+
146
+ it "should accept complex classes (like {String=>Fixnum}) for its schema" do
147
+ data[:foo] = {"a" => 1}
148
+ lambda {
149
+ data[:foo] = {String => Fixnum}
150
+ }.should_not raise_error
151
+ end
152
+
132
153
  it "can override implicitly declared schema by sub-struct schema" do
133
154
  data[:foo] = {}
134
155
  data[:foo].should == {}
data/spec/time_spec.rb CHANGED
@@ -22,5 +22,12 @@ describe Typed::Hash do
22
22
  }.should raise_error(Must::Invalid)
23
23
  end
24
24
  end
25
+
26
+ describe "#utc" do
27
+ subject { data["now"] = 100; data.utc("now") }
28
+ its(:class) { should == Time }
29
+ its(:zone) { should == "UTC" }
30
+ its(:to_i) { should == 100 }
31
+ end
25
32
  end
26
33
 
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: 17
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-31 00:00:00 +09:00
19
- default_executable:
18
+ date: 2012-07-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: activesupport
@@ -94,7 +93,6 @@ files:
94
93
  - spec/spec_helper.rb
95
94
  - spec/time_spec.rb
96
95
  - typed.gemspec
97
- has_rdoc: true
98
96
  homepage: https://github.com/maiha/typed
99
97
  licenses: []
100
98
 
@@ -124,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
122
  requirements: []
125
123
 
126
124
  rubyforge_project: typed
127
- rubygems_version: 1.3.7
125
+ rubygems_version: 1.8.15
128
126
  signing_key:
129
127
  specification_version: 3
130
128
  summary: A Ruby library for Typed variables