Method: CFoundry::V2::Model#create!

Defined in:
lib/cfoundry/v2/model.rb

#create!Object

this does a bit of extra processing to allow for ‘delete!’ followed by ‘create!’



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cfoundry/v2/model.rb', line 69

def create!
  payload = {}

  @manifest ||= {}
  @manifest[:entity] ||= {}

  @manifest[:entity].each do |k, v|
    if v.is_a?(Hash) && v.key?(:metadata)
      # skip; there's a _guid attribute already
    elsif v.is_a?(Array) && !v.empty? && v.all? { |x|
            x.is_a?(Hash) && x.key?(:metadata)
          }
      singular = k.to_s.sub(/s$/, "")

      payload[:"#{singular}_guids"] = v.collect do |x|
        if x.is_a?(Hash) && x.key?(:metadata)
          x[:metadata][:guid]
        else
          x
        end
      end
    elsif k.to_s.end_with?("_url")
    else
      payload[k] = v
    end
  end

  @manifest = @client.base.send(:"create_#{object_name}", payload)

  @guid = @manifest[:metadata][:guid]

  @diff.clear

  true
end