Return a JSON string representing an array of all objects in this dataset.
Takes the same options as the instance method, and passes them to every
instance. Additionally, respects the following options:
349: def to_json(*a)
350: if opts = a.first.is_a?(Hash)
351: opts = model.json_serializer_opts.merge(a.first)
352: a = []
353: else
354: opts = model.json_serializer_opts
355: end
356:
357: case collection_root = opts[:root]
358: when nil, false, :instance
359: collection_root = false
360: else
361: opts = opts.dup
362: unless collection_root == :both
363: opts.delete(:root)
364: end
365: unless collection_root.is_a?(String)
366: collection_root = model.send(:pluralize, model.send(:underscore, model.send(:demodulize, model.to_s)))
367: end
368: end
369:
370: res = if row_proc
371: array = if opts[:array]
372: opts = opts.dup
373: opts.delete(:array)
374: else
375: all
376: end
377: array.map{|obj| Literal.new(Sequel.object_to_json(obj, opts))}
378: else
379: all
380: end
381:
382: if collection_root
383: Sequel.object_to_json({collection_root => res}, *a)
384: else
385: Sequel.object_to_json(res, *a)
386: end
387: end