lib/cfoundry/v2/model.rb in cfoundry-0.3.51 vs lib/cfoundry/v2/model.rb in cfoundry-0.3.52

- old
+ new

@@ -76,28 +76,38 @@ obj = opts[:as] || name kls = obj.to_s.capitalize.gsub(/(.)_(.)/) do $1 + $2.upcase end + default = opts[:default] + + if has_default = opts.key?(:default) + defaults[:"#{name}_guid"] = default + end + define_method(name) { if @manifest && @manifest[:entity].key?(name) @client.send(:"make_#{obj}", @manifest[:entity][name]) elsif url = send("#{name}_url") @client.send(:"#{obj}_from", url, opts[:depth] || 1) + else + default end } define_method(:"#{name}_url") { manifest[:entity][:"#{name}_url"] } define_method(:"#{name}=") { |x| - Model.validate_type(x, CFoundry::V2.const_get(kls)) + unless has_default && x == default + Model.validate_type(x, CFoundry::V2.const_get(kls)) + end @manifest ||= {} @manifest[:entity] ||= {} @manifest[:entity][:"#{name}_guid"] = - @diff[:"#{name}_guid"] = x.guid + @diff[:"#{name}_guid"] = x && x.guid } end def to_many(plural, opts = {}) singular = plural.to_s.sub(/s$/, "").to_sym