Method: Chef::DataBagItem#save

Defined in:
lib/chef/data_bag_item.rb

#save(item_id = ) ⇒ Object

Save this Data Bag Item via RESTful API



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/chef/data_bag_item.rb', line 174

def save(item_id = @raw_data["id"])
  r = chef_server_rest
  begin
    if Chef::Config[:why_run]
      Chef::Log.warn("In why-run mode, so NOT performing data bag item save.")
    else
      r.put("data/#{data_bag}/#{item_id}", self)
    end
  rescue Net::HTTPClientException => e
    raise e unless e.response.code == "404"

    r.post("data/#{data_bag}", self)
  end
  self
end