Return a JSON string representing an array of all objects in this dataset.
Takes the same options as the the instance method, and passes them to every
instance. Additionally, respects the following options:
369: def to_json(*a)
370: if opts = a.first.is_a?(Hash)
371: opts = model.json_serializer_opts.merge(a.first)
372: a = []
373: else
374: opts = model.json_serializer_opts
375: end
376:
377: collection_root = case opts[:root]
378: when nil, false, :instance
379: false
380: when :collection
381: opts = opts.dup
382: opts.delete(:root)
383: opts[:naked] = true unless opts.has_key?(:naked)
384: true
385: when :both
386: true
387: else
388: Sequel::Deprecation.deprecate('The to_json :root=>true option will mean :root=>:collection starting in Sequel 4. Use :root=>:both if you want to wrap both the collection and each item in a wrapper.')
389: true
390: end
391:
392: res = if row_proc
393: array = if opts[:array]
394: opts = opts.dup
395: opts.delete(:array)
396: else
397: all
398: end
399: array.map{|obj| Literal.new(Sequel.object_to_json(obj, opts))}
400: else
401: all
402: end
403:
404: if collection_root
405: Sequel.object_to_json({model.send(:pluralize, model.send(:underscore, model.to_s)) => res}, *a)
406: else
407: Sequel.object_to_json(res, *a)
408: end
409: end