ohm-contrib 0.0.15 → 0.0.16
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.
- data/VERSION +1 -1
- data/lib/ohm/contrib/typecast.rb +19 -0
- data/lib/ohm/contrib.rb +1 -1
- data/ohm-contrib.gemspec +2 -2
- data/test/test_ohm_typecast.rb +54 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.16
|
data/lib/ohm/contrib/typecast.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'bigdecimal'
|
2
2
|
require 'time'
|
3
3
|
require 'date'
|
4
|
+
require 'forwardable'
|
4
5
|
|
5
6
|
module Ohm
|
6
7
|
# Provides all the primitive types. The following are included:
|
@@ -68,6 +69,15 @@ module Ohm
|
|
68
69
|
end
|
69
70
|
|
70
71
|
class Time < Primitive
|
72
|
+
class << self
|
73
|
+
extend Forwardable
|
74
|
+
def_delegators :Time,
|
75
|
+
:_load, :apply_offset, :at, :gm, :httpdate, :json_create, :local,
|
76
|
+
:make_time, :mktime, :month_days, :now, :parse, :rfc2822,
|
77
|
+
:strptime, :utc, :w3cdtf, :xmlschema, :yaml_new, :zone_offset,
|
78
|
+
:zone_utc?
|
79
|
+
end
|
80
|
+
|
71
81
|
protected
|
72
82
|
def object
|
73
83
|
::Time.parse(@raw)
|
@@ -75,6 +85,15 @@ module Ohm
|
|
75
85
|
end
|
76
86
|
|
77
87
|
class Date < Primitive
|
88
|
+
class << self
|
89
|
+
extend Forwardable
|
90
|
+
def_delegators :Date,
|
91
|
+
:_parse, :_strptime, :civil, :commercial, :gregorian_leap?, :jd,
|
92
|
+
:json_create, :julian_leap?, :now, :nth_kday, :ordinal, :parse, :s3e,
|
93
|
+
:strptime, :today, :valid_civil?, :valid_commercial?, :valid_jd?,
|
94
|
+
:valid_ordinal?, :weeknum
|
95
|
+
end
|
96
|
+
|
78
97
|
protected
|
79
98
|
def object
|
80
99
|
::Date.parse(@raw)
|
data/lib/ohm/contrib.rb
CHANGED
data/ohm-contrib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ohm-contrib}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.16"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril David"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-25}
|
13
13
|
s.description = %q{Highly decoupled drop-in functionality for Ohm models}
|
14
14
|
s.email = %q{cyx.ucron@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_ohm_typecast.rb
CHANGED
@@ -200,6 +200,33 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
200
200
|
include Ohm::Typecast
|
201
201
|
|
202
202
|
attribute :created_at, Time
|
203
|
+
|
204
|
+
def now
|
205
|
+
Time.now
|
206
|
+
end
|
207
|
+
|
208
|
+
def time
|
209
|
+
Time
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
test "still able to access top level Time" do
|
214
|
+
post = Post.new
|
215
|
+
assert_equal post.now.to_s, Time.now.to_s
|
216
|
+
end
|
217
|
+
|
218
|
+
test "responds to all ::Time class methods" do
|
219
|
+
post = Post.new
|
220
|
+
methods = [
|
221
|
+
:_load, :apply_offset, :at, :gm, :httpdate, :json_create, :local,
|
222
|
+
:make_time, :mktime, :month_days, :new, :now, :parse, :rfc2822,
|
223
|
+
:strptime, :utc, :w3cdtf, :xmlschema, :yaml_new, :zone_offset,
|
224
|
+
:zone_utc?
|
225
|
+
]
|
226
|
+
|
227
|
+
methods.each do |m|
|
228
|
+
assert_respond_to post.time, m
|
229
|
+
end
|
203
230
|
end
|
204
231
|
|
205
232
|
test "handles nil case correctly" do
|
@@ -245,6 +272,32 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
245
272
|
def today
|
246
273
|
::Date.today
|
247
274
|
end
|
275
|
+
|
276
|
+
def date
|
277
|
+
Date
|
278
|
+
end
|
279
|
+
|
280
|
+
def base_today
|
281
|
+
Date.today
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
test "still able to get top level methods" do
|
286
|
+
assert_equal Date.today, Post.new.base_today
|
287
|
+
end
|
288
|
+
|
289
|
+
test "responds to all the class methods" do
|
290
|
+
post = Post.new
|
291
|
+
|
292
|
+
methods = [
|
293
|
+
:_parse, :_strptime, :civil, :commercial, :gregorian_leap?, :jd,
|
294
|
+
:json_create, :julian_leap?, :now, :nth_kday, :ordinal, :parse, :s3e,
|
295
|
+
:strptime, :today, :valid_civil?, :valid_commercial?, :valid_jd?,
|
296
|
+
:valid_ordinal?, :weeknum
|
297
|
+
]
|
298
|
+
methods.each do |m|
|
299
|
+
assert_respond_to post.date, m
|
300
|
+
end
|
248
301
|
end
|
249
302
|
|
250
303
|
test "handles nil case correctly" do
|
@@ -282,4 +335,4 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
282
335
|
assert_equal Date.today, Post.new.today
|
283
336
|
end
|
284
337
|
end
|
285
|
-
end
|
338
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 16
|
9
|
+
version: 0.0.16
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-25 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|