Skip to content

Commit b159685

Browse files
committed
inline the to_integer conversion - without the need to catch exceptions from to_i
1 parent 15f4755 commit b159685

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/arjdbc/postgresql/column.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,15 @@ def type_cast(value, type = false) # AR >= 4.0 version
172172
from = self.class.string_to_time(extracted[:from])
173173
to = self.class.string_to_time(extracted[:to])
174174
when 'int4', 'int8' # :integer
175-
from = to_integer(extracted[:from]) rescue value ? 1 : 0
175+
from = extracted[:from]
176+
unless (from.respond_to?(:infinite?) && from.infinite?)
177+
from = from.respond_to?(:to_i) ? from.to_i : ( value ? 1 : 0 )
178+
end
176179
from += 1 if extracted[:exclude_start]
177-
to = to_integer(extracted[:to]) rescue value ? 1 : 0
180+
to = extracted[:to]
181+
unless (to.respond_to?(:infinite?) && to.infinite?)
182+
to = to.respond_to?(:to_i) ? to.to_i : ( value ? 1 : 0 )
183+
end
178184
else
179185
return value
180186
end
@@ -321,10 +327,6 @@ def infinity(options = {})
321327
::Float::INFINITY * (options[:negative] ? -1 : 1)
322328
end if AR4_COMPAT
323329

324-
def to_integer(value)
325-
(value.respond_to?(:infinite?) && value.infinite?) ? value : value.to_i
326-
end if AR4_COMPAT
327-
328330
# @note Based on *active_record/connection_adapters/postgresql/cast.rb* (4.0).
329331
module Cast
330332

0 commit comments

Comments
 (0)