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