#put(request) ⇒ Object

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

# File 'lib/chef_zero/endpoints/rest_object_endpoint.rb', line 21defput(request)# We grab the old body to trigger a 404 if it doesn't exist
old_body=get_data(request)request_json=FFI_Yajl::Parser.parse(request.body,:create_additions=>false)key=identity_keys.map{|k|request_json[k]}.select{|v|v}.firstkey||=request.rest_path[-1]# If it's a rename, check for conflict and delete the old value
rename=key!=request.rest_path[-1]ifrenamebegincreate_data(request,request.rest_path[0..-2],key,request.body,:data_store_exceptions)rescueDataStore::DataAlreadyExistsErrorreturnerror(409,"Cannot rename '#{request.rest_path[-1]}' to '#{key}': '#{key}' already exists")enddelete_data(request)already_json_response(201,populate_defaults(request,request.body))elseset_data(request,request.rest_path,request.body)already_json_response(200,populate_defaults(request,request.body))endend