lib/cfoundry/v2/model.rb in cfoundry-0.3.4 vs lib/cfoundry/v2/model.rb in cfoundry-0.3.5

- old
+ new

@@ -26,11 +26,14 @@ define_method(name) { if manifest[:entity].key? name @client.send(:"make_#{obj}", manifest[:entity][name]) else - @client.send(:"#{name}_from", send("#{obj}_url")) + @client.send( + :"#{obj}_from", + send("#{name}_url"), + opts[:depth] || 1) end } define_method(:"#{name}_url") { manifest[:entity][:"#{name}_url"] @@ -44,19 +47,24 @@ } end def to_many(plural, opts = {}) singular = plural.to_s.sub(/s$/, "").to_sym + object = opts[:as] || singular + plural_object = object.to_s.sub(/s$/, "").to_sym define_method(plural) { if manifest[:entity].key? plural manifest[:entity][plural].collect do |json| @client.send(:"make_#{object}", json) end else - @client.send(:"#{plural}_from", send("#{plural}_url")) + @client.send( + :"#{plural_object}_from", + send("#{plural}_url"), + opts[:depth] || 1) end } define_method(:"#{plural}_url") { manifest[:entity][:"#{plural}_url"] @@ -113,10 +121,10 @@ def create! @manifest = @client.base.send( :"create_#{object_name}", - @manifest[:entity].merge(self.class.defaults)) + self.class.defaults.merge(@manifest[:entity])) @id = @manifest[:metadata][:guid] true end