7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fat_secret/relations/has_many.rb', line 7
def has_many(type, options = {})
define_method type do
@servings ||= HasManyProxy.new([])
if options[:autoload] && @servings.blank? && id
self.class.get(id).servings
else
@servings
end
end
define_method "#{type}=" do |array|
klass = "FatSecret::#{type.to_s.singularize.classify}".constantize
servings = array[type.to_s.singularize].map do |attrs|
klass.new(attrs)
end
@servings = HasManyProxy.new(servings)
end
end
|