Module | Sequel::EvalInspect |
In: |
lib/sequel/extensions/eval_inspect.rb
|
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 27 27: def eval_inspect(obj) 28: case obj 29: when Sequel::SQL::Blob, Sequel::LiteralString, BigDecimal 30: "#{obj.class}.new(#{obj.to_s.inspect})" 31: when Sequel::SQL::ValueList 32: "#{obj.class}.new(#{obj.to_a.inspect})" 33: when Array 34: "[#{obj.map{|o| eval_inspect(o)}.join(', ')}]" 35: when Hash 36: "{#{obj.map{|k, v| "#{eval_inspect(k)} => #{eval_inspect(v)}"}.join(', ')}}" 37: when Time 38: datepart = "%Y-%m-%dT" unless obj.is_a?(Sequel::SQLTime) 39: "#{obj.class}.parse(#{obj.strftime("#{datepart}%T.%N%z").inspect})#{'.utc' if obj.utc?}" 40: when DateTime 41: # Ignore date of calendar reform 42: "DateTime.parse(#{obj.strftime('%FT%T.%N%z').inspect})" 43: when Date 44: # Ignore offset and date of calendar reform 45: "Date.new(#{obj.year}, #{obj.month}, #{obj.day})" 46: else 47: obj.inspect 48: end 49: end