Class: Riddl::Utils::Properties::DelContent

Inherits:
Implementation show all
Defined in:
lib/ruby/riddl/utils/properties.rb

Overview

}}}

Instance Method Summary collapse

Methods inherited from Implementation

#headers, #initialize, #status

Constructor Details

This class inherits a constructor from Riddl::Implementation

Instance Method Details

#responseObject

{{{



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/ruby/riddl/utils/properties.rb', line 401

def response
  backend = @a[0]
  handler = @a[1]

  property = @r[1]
  minor    = Riddl::Protocols::Utils::unescape(@r[2])

  unless backend.modifiable?(property)
    @status = 500
    return # change properties.schema
  end

  path = "/p:properties/*[name()=\"#{property}\"]#{minor.nil? ? '' : "/p:#{minor}"}"
  nodes = backend.data.find(path)
  if nodes.empty?
    @status = 404
    return # this property does not exist
  end

  backend.modify do |doc|
    doc.find(path).delete_all!
  end || begin
    @status = 400
    return # bad request
  end

  EM.defer{handler.property(property).delete} unless handler.nil?
  return
end