361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
# File 'lib/cfoundry/v2/model_magic.rb', line 361
def has_summary(actions = {})
define_method(:summary) do
@client.base.get("v2", plural_object_name, @guid, "summary", :accept => :json)
end
define_method(:summarize!) do |*args|
body, _ = args
body ||= summary
body.each do |key, val|
if act = actions[key]
instance_exec(val, &act)
elsif self.class.attributes[key]
self.send(:"#{key}=", val)
elsif self.class.to_many_relations[key]
singular = key.to_s.sub(/s$/, "").to_sym
vals = val.collect do |sub|
obj = @client.send(singular, sub[:guid], true)
obj.summarize! sub
obj
end
self.send(:"#{key}=", vals)
elsif self.class.to_one_relations[key]
obj = @client.send(key, val[:guid], true)
obj.summarize! val
self.send(:"#{key}=", obj)
end
end
nil
end
end
|