Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid-cached-json/array.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



16
17
18
19
# File 'lib/mongoid-cached-json/array.rb', line 16

def as_json(options = {})
  json_keys, json = as_json_partial(options)
  Mongoid::CachedJson.materialize_json_references_with_read_multi(json_keys, json)
end

#as_json_partial(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/mongoid-cached-json/array.rb', line 2

def as_json_partial(options = {})
  json_keys = nil
  json = map do |i|
    if i.respond_to?(:as_json_partial)
      partial_json_keys, json = i.as_json_partial(options)
      json_keys = json_keys ? json_keys.merge_set(partial_json_keys) : partial_json_keys
      json
    else
      i.as_json(options)
    end
  end
  [json_keys, json]
end