Module: Core::Io::Collection

Included in:
Io::ActiveRecord::Relation, Io::Array
Defined in:
app/api/core/io/collection.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/api/core/io/collection.rb', line 3

def as_json(options = {})
  results, base_stream = options[:object], options[:stream]

  base_stream.attribute(:size, size_for(results))
  base_stream.array(options[:response].io.json_root.to_s.pluralize, results) do |stream, object|
    stream.open do
      ::Core::Io::Registry
        .instance
        .lookup_for_object(object)
        .object_json(object, options.merge(stream: stream, target: object, nested: true))
    end
  end
end