Class: Riddl::Utils::Properties::AddContent

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

{{{



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# 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