9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/serialization.rb', line 9
def add_includes_with_breakfast(&block)
if include_associations = options.delete(:include)
include_has_options = include_associations.is_a?(Hash)
associations = include_has_options ? include_associations.keys : Array(include_associations)
for association in associations
records = case @record.class.reflect_on_association(association).macro
when :has_many, :has_and_belongs_to_many
@record.send(association).to_a
when :has_one, :belongs_to
@record.send(association)
end
unless records.nil?
association_options = include_has_options ? include_associations[association] : {}
association_options.reverse_merge!(:style => options[:style], :include => nil)
opts = options.except(:only, :except, :methods).merge(association_options)
yield(association, records, opts)
end
end
options[:include] = include_associations
end
end
|