Module Sequel::EvalInspect
In: lib/sequel/extensions/eval_inspect.rb

Methods

Public Instance methods

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.

[Source]

    # File lib/sequel/extensions/eval_inspect.rb, line 27
27:     def eval_inspect(obj)
28:       case obj
29:       when Sequel::SQL::Blob, Sequel::LiteralString, Sequel::SQL::ValueList
30:         "#{obj.class}.new(#{obj.inspect})"
31:       when Array
32:         "[#{obj.map{|o| eval_inspect(o)}.join(', ')}]"
33:       when Hash
34:         "{#{obj.map{|k, v| "#{eval_inspect(k)} => #{eval_inspect(v)}"}.join(', ')}}"
35:       when Time
36:         datepart = "%Y-%m-%dT" unless obj.is_a?(Sequel::SQLTime)
37:         if RUBY_VERSION < '1.9'
38:         # :nocov:
39:           # Time on 1.8 doesn't handle %N (or %z on Windows), manually set the usec value in the string
40:           hours, mins = obj.utc_offset.divmod(3600)
41:           mins /= 60
42:           "#{obj.class}.parse(#{obj.strftime("#{datepart}%H:%M:%S.#{sprintf('%06i%+03i%02i', obj.usec, hours, mins)}").inspect})#{'.utc' if obj.utc?}"
43:         # :nocov:
44:         else
45:           "#{obj.class}.parse(#{obj.strftime("#{datepart}%T.%N%z").inspect})#{'.utc' if obj.utc?}"
46:         end
47:       when DateTime
48:         # Ignore date of calendar reform
49:         "DateTime.parse(#{obj.strftime('%FT%T.%N%z').inspect})"
50:       when Date
51:         # Ignore offset and date of calendar reform
52:         "Date.new(#{obj.year}, #{obj.month}, #{obj.day})"
53:       when BigDecimal
54:         "BigDecimal.new(#{obj.to_s.inspect})"
55:       else
56:         obj.inspect
57:       end
58:     end

[Validate]