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:
316: def to_json(*a)
317: if opts = a.first.is_a?(Hash)
318: opts = model.json_serializer_opts.merge(a.first)
319: a = []
320: else
321: opts = model.json_serializer_opts
322: end
323:
324: case collection_root = opts[:root]
325: when nil, false, :instance
326: collection_root = false
327: else
328: opts = opts.dup
329: unless collection_root == :both
330: opts.delete(:root)
331: end
332: unless collection_root.is_a?(String)
333: collection_root = model.send(:pluralize, model.send(:underscore, model.to_s))
334: end
335: end
336:
337: res = if row_proc
338: array = if opts[:array]
339: opts = opts.dup
340: opts.delete(:array)
341: else
342: all
343: end
344: array.map{|obj| Literal.new(Sequel.object_to_json(obj, opts))}
345: else
346: all
347: end
348:
349: if collection_root
350: Sequel.object_to_json({collection_root => res}, *a)
351: else
352: Sequel.object_to_json(res, *a)
353: end
354: end