Sha256: 3614830e44a8e1d3055efbc470a30592c8c9a8d17244902590f4314848955292

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Reactor
  module WhereQuery
    def where(key, value)
      request = Cm::XmlRequest.prepare do |xml|
        xml.where_tag!(self.base_name) do
          xml.tag!(key) do
            if value
              xml.text!(value)
            end
          end
        end

        xml.get_tag!(self.base_name) do
          self.attributes.each do |_, xml_attribute|
            xml.tag!(xml_attribute.name)
          end
        end
      end

      response = request.execute!
      result = response.xpath("//#{self.base_name}")
      result = [result] unless result.kind_of?(Array)
      result.map do |elem|
        values = {}
        values = self.response_handler.multiple(elem, self.attributes.values)
        instance  = self.new
        values.each do |name, value|
          pair = self.attributes.find {|n, a| a.name.to_sym == name.to_sym }
          attribute = pair[0]
          instance.send(:"#{attribute}=", value)
        end
        instance
      end
    rescue Cm::XmlRequestError
      []
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_reactor-1.26.1 lib/reactor/tools/where_query.rb
infopark_reactor-1.26.0 lib/reactor/tools/where_query.rb
infopark_reactor-1.25.2 lib/reactor/tools/where_query.rb