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

[Validate]