Class: DynamicsCRM::XML::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamics_crm/xml/query.rb

Overview

Represents Query XML fragment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_name) ⇒ Query

Returns a new instance of Query.



8
9
10
# File 'lib/dynamics_crm/xml/query.rb', line 8

def initialize(entity_name)
  @entity_name = entity_name
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



6
7
8
# File 'lib/dynamics_crm/xml/query.rb', line 6

def columns
  @columns
end

#criteriaObject

Returns the value of attribute criteria.



6
7
8
# File 'lib/dynamics_crm/xml/query.rb', line 6

def criteria
  @criteria
end

#entity_nameObject

Returns the value of attribute entity_name.



6
7
8
# File 'lib/dynamics_crm/xml/query.rb', line 6

def entity_name
  @entity_name
end

Instance Method Details

#to_xml(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dynamics_crm/xml/query.rb', line 12

def to_xml(options={})
  namespace = options[:namespace] ? options[:namespace] : "b"

  column_set = ColumnSet.new(columns)
  @criteria ||= Criteria.new

  xml = %Q{
      #{column_set.to_xml(namespace: namespace, camel_case: true)}
      #{@criteria.to_xml(namespace: namespace)}
      <#{namespace}:Distinct>false</#{namespace}:Distinct>
      <#{namespace}:EntityName>#{entity_name}</#{namespace}:EntityName>
      <#{namespace}:LinkEntities />
      <#{namespace}:Orders />
    }

  if options[:exclude_root].nil?
    xml = %Q{<query i:type="b:QueryExpression" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        #{xml}
    </query>}
  end
  return xml
end