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:
388: def to_json(*a)
389: if opts = a.first.is_a?(Hash)
390: opts = model.json_serializer_opts.merge(a.first)
391: a = []
392: else
393: opts = model.json_serializer_opts
394: end
395:
396: case collection_root = opts[:root]
397: when nil, false, :instance
398: collection_root = false
399: else
400: opts = opts.dup
401: unless collection_root == :both
402: opts.delete(:root)
403: end
404: unless collection_root.is_a?(String)
405: collection_root = model.send(:pluralize, model.send(:underscore, model.send(:demodulize, model.to_s)))
406: end
407: end
408:
409: res = if row_proc || @opts[:eager_graph]
410: array = if opts[:array]
411: opts = opts.dup
412: opts.delete(:array)
413: else
414: all
415: end
416: array.map{|obj| Literal.new(Sequel.object_to_json(obj, opts, &opts[:instance_block]))}
417: else
418: all
419: end
420:
421: res = {collection_root => res} if collection_root
422: res = yield res if block_given?
423:
424: Sequel.object_to_json(res, *a)
425: end