Class: Riddl::Utils::Properties::Query

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

{{{



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ruby/riddl/utils/properties.rb', line 166

def response
  backend = @a[0]
  handler = @a[1]
  EM.defer{handler.read} unless handler.nil?
  query = (@p[0].value.to_s.strip.empty? ? '*' : @p[0].value)

  begin
    e = backend.data.find(query)
  rescue => e
    prop = XML::Smart::string("<not-existing xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>").to_s
    return Riddl::Parameter::Complex.new("value","text/xml",prop.to_s)
  end
  if e.class == XML::Smart::Dom::NodeSet
    if e.any?
      prop = XML::Smart::string("<value xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>")
      prop.root.add(e)
    else
      prop = XML::Smart::string("<not-existing xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>").to_s
    end
    return Riddl::Parameter::Complex.new("value","text/xml",prop.to_s)
  else
    return Riddl::Parameter::Simple.new("value",e.to_s)
  end
end