pg_json 0.1.26 → 0.1.27
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pg_json/sequel/pg_json.rb +11 -29
- metadata +1 -1
@@ -1,4 +1,9 @@
|
|
1
1
|
require "date"
|
2
|
+
|
3
|
+
# puts "2012-04-21" =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
|
4
|
+
# puts "00:00:00" =~ /^[0-9]{2}:[0-9]{2}:[0-9]{2}$/
|
5
|
+
# puts "2012-04-21T00:00:00+0200" =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{4}$/
|
6
|
+
|
2
7
|
#
|
3
8
|
# JSON_TYPES = {} unless defined? JSON_TYPES
|
4
9
|
# JSON_TYPES[:date] = lambda do |v|
|
@@ -24,40 +29,17 @@ class Hash
|
|
24
29
|
v.json_typify!
|
25
30
|
else
|
26
31
|
if !v.nil? && v.is_a?(String)
|
27
|
-
if
|
28
|
-
|
29
|
-
elsif
|
30
|
-
|
31
|
-
elsif
|
32
|
-
|
32
|
+
if v =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{4}$/
|
33
|
+
DateTime.parse(v).to_time
|
34
|
+
elsif v =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
|
35
|
+
v.to_date
|
36
|
+
elsif v =~ /^[0-9]{2}:[0-9]{2}:[0-9]{2}$/
|
37
|
+
v.to_time
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
38
|
-
# def json_typify!
|
39
|
-
# replacements = []
|
40
|
-
# self.each do |k, v|
|
41
|
-
# if v.is_a? Hash
|
42
|
-
# if v[:__type__]
|
43
|
-
# if v[:value]
|
44
|
-
# # puts "::: #{v.inspect}"
|
45
|
-
# replacements << [k, JSON_TYPES[v[:__type__].to_sym].call(v[:value])]
|
46
|
-
# else
|
47
|
-
# replacements << [k, nil]
|
48
|
-
# end
|
49
|
-
# else
|
50
|
-
# v.json_typify!
|
51
|
-
# end
|
52
|
-
# elsif v.is_a? Array
|
53
|
-
# v.json_typify!
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# replacements.each do |r|
|
57
|
-
# k, v = r
|
58
|
-
# self[k] = v
|
59
|
-
# end
|
60
|
-
# end
|
61
43
|
|
62
44
|
def recursively_symbolize_keys!
|
63
45
|
self.symbolize_keys!
|