class Riddl::Utils::Properties::AddContent

Public Instance Methods

response() click to toggle source
# File lib/ruby/riddl/utils/properties.rb, line 368
def response
  backend = @a[0]
  handler = @a[1]

  property = @r[1]
  value = @p.detect{|p| p.name == 'value'}.value

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

  path = "/p:properties/p:#{property}"
  node = backend.data.find(path)
  if node.empty?
    @status = 404
    return # this property does not exist
  end

  newstuff = XML::Smart.string(value)
  backend.modify do |doc|
    node = doc.find(path)
    node.first.add newstuff.root
  end || begin
    @status = 400
    return # bad request
  end

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