Module: Toy::AssociationSerialization

Extended by:
ActiveSupport::Concern
Includes:
Serialization
Included in:
Store
Defined in:
lib/toy/association_serialization.rb

Instance Method Summary collapse

Methods included from Serialization

#serializable_attributes

Instance Method Details

#serializable_hash(options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/toy/association_serialization.rb', line 6

def serializable_hash(options = nil)
  options ||= {}
  super.tap { |hash|
    serializable_add_includes(options) do |association, records, opts|
      hash[association] = records.is_a?(Enumerable) ?
        records.map { |r| r.serializable_hash(opts) } :
        records.serializable_hash(opts)
    end
  }
end