Module: Sequel::Plugins::JsonSerializer::DatasetMethods

Defined in:
lib/sequel/plugins/json_serializer.rb

Instance Method Summary collapse

Instance Method Details

#to_json(*a) ⇒ Object

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.



199
200
201
202
203
204
205
206
207
208
# File 'lib/sequel/plugins/json_serializer.rb', line 199

def to_json(*a)
  if opts = a.first.is_a?(Hash)
    opts = model.json_serializer_opts.merge(a.first)
    a = []
  else
    opts = model.json_serializer_opts
  end
  res = row_proc ? all.map{|obj| Literal.new(obj.to_json(opts))} : all
  opts[:root] ? {model.send(:pluralize, model.send(:underscore, model.to_s)) => res}.to_json(*a) : res.to_json(*a)
end