module Sequel::EvalInspect
Public Instance Methods
eval_inspect(obj)
click to toggle source
Special case objects where inspect does not generally produce input suitable for eval. Used by Sequel::SQL::Expression#inspect so that it can produce a string suitable for eval even if components of the expression have inspect methods that do not produce strings suitable for eval.
# File lib/sequel/extensions/eval_inspect.rb, line 26 def eval_inspect(obj) case obj when BigDecimal "BigDecimal(#{obj.to_s.inspect})" when Sequel::SQL::Blob, Sequel::LiteralString "#{obj.class}.new(#{obj.to_s.inspect})" when Sequel::SQL::ValueList "#{obj.class}.new(#{obj.to_a.inspect})" when Array "[#{obj.map{|o| eval_inspect(o)}.join(', ')}]" when Hash "{#{obj.map{|k, v| "#{eval_inspect(k)} => #{eval_inspect(v)}"}.join(', ')}}" when Time datepart = "%Y-%m-%dT" unless obj.is_a?(Sequel::SQLTime) "#{obj.class}.parse(#{obj.strftime("#{datepart}%T.%N%z").inspect})#{'.utc' if obj.utc?}" when DateTime # Ignore date of calendar reform "DateTime.parse(#{obj.strftime('%FT%T.%N%z').inspect})" when Date # Ignore offset and date of calendar reform "Date.new(#{obj.year}, #{obj.month}, #{obj.day})" else obj.inspect end end