gotime-cassandra_object 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gotime-cassandra_object}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Koziarski", "grantr"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-17}
|
13
13
|
s.description = %q{Cassandra ActiveModel}
|
14
14
|
s.email = %q{grantr@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -3,6 +3,7 @@ module CassandraObject
|
|
3
3
|
REGEX = /\A[-+]?\d+\Z/
|
4
4
|
def encode(int)
|
5
5
|
return '' if int.nil?
|
6
|
+
int = int.to_i if int.kind_of?(String) && int.match(REGEX)
|
6
7
|
raise ArgumentError.new("#{self} requires an Integer. You passed #{int.inspect}") unless int.kind_of?(Integer)
|
7
8
|
int.to_s
|
8
9
|
end
|
@@ -20,6 +21,7 @@ module CassandraObject
|
|
20
21
|
REGEX = /\A[-+]?\d+(\.\d+)\Z/
|
21
22
|
def encode(float)
|
22
23
|
return '' if float.nil?
|
24
|
+
float = float.to_f if float.kind_of?(String) && float.match(REGEX)
|
23
25
|
raise ArgumentError.new("#{self} requires a Float") unless float.kind_of?(Float)
|
24
26
|
float.to_s
|
25
27
|
end
|
@@ -38,6 +40,7 @@ module CassandraObject
|
|
38
40
|
REGEX = /\A\d{4}-\d{2}-\d{2}\Z/
|
39
41
|
def encode(date)
|
40
42
|
return '' if date.nil?
|
43
|
+
date = Date.parse(date) if date.kind_of?(String) && date.match(REGEX)
|
41
44
|
raise ArgumentError.new("#{self} requires a Date") unless date.kind_of?(Date)
|
42
45
|
date.strftime(FORMAT)
|
43
46
|
end
|
@@ -63,6 +66,7 @@ module CassandraObject
|
|
63
66
|
|
64
67
|
def encode(time)
|
65
68
|
return '' if time.nil?
|
69
|
+
time = Time.parse(time) if time.kind_of?(String) && time.match(REGEX)
|
66
70
|
raise ArgumentError.new("#{self} requires a Time") unless time.kind_of?(Time)
|
67
71
|
time.xmlschema(6)
|
68
72
|
end
|
@@ -79,13 +83,16 @@ module CassandraObject
|
|
79
83
|
module TimeWithZoneType
|
80
84
|
def encode(time)
|
81
85
|
return '' if time.nil?
|
82
|
-
|
86
|
+
time = Time.zone.parse(time) if time.kind_of?(String) && time.match(TimeType::REGEX)
|
87
|
+
raise ArgumentError.new("#{self} requires a Time") unless time.kind_of?(Time)
|
88
|
+
time.utc.xmlschema(6)
|
83
89
|
end
|
84
90
|
module_function :encode
|
85
91
|
|
86
92
|
def decode(str)
|
87
93
|
return nil if str.empty?
|
88
|
-
|
94
|
+
raise ArgumentError.new("#{str} isn't a String that looks like a Time") unless str.kind_of?(String) && str.match(TimeType::REGEX)
|
95
|
+
Time.xmlschema(str).in_time_zone
|
89
96
|
end
|
90
97
|
module_function :decode
|
91
98
|
end
|
@@ -136,12 +143,13 @@ module CassandraObject
|
|
136
143
|
end
|
137
144
|
|
138
145
|
module BooleanType
|
139
|
-
|
146
|
+
TRUE_VALS = [true, 'true', '1']
|
147
|
+
FALSE_VALS = [false, 'false', '0', nil]
|
140
148
|
def encode(bool)
|
141
|
-
unless
|
142
|
-
|
149
|
+
unless TRUE_VALS.any? { |a| bool == a } || FALSE_VALS.any?{ |a| bool == a }
|
150
|
+
raise ArgumentError.new("#{self} requires a Boolean or nil")
|
143
151
|
end
|
144
|
-
bool ? '1' : '0'
|
152
|
+
TRUE_VALS.include?(bool) ? '1' : '0'
|
145
153
|
end
|
146
154
|
module_function :encode
|
147
155
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 7
|
9
|
+
version: 0.7.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Koziarski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-17 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
213
|
requirements:
|
214
214
|
- - ">="
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
hash: -
|
216
|
+
hash: -226474256886539699
|
217
217
|
segments:
|
218
218
|
- 0
|
219
219
|
version: "0"
|