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