Class: DynamicsCRM::XML::QueryExpression

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

Overview

Represents QueryExpression XML fragment.

Direct Known Subclasses

Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_name) ⇒ QueryExpression

Returns a new instance of QueryExpression.



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

def initialize(entity_name)
  @entity_name = entity_name
  @criteria = Criteria.new
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/dynamics_crm/xml/query_expression.rb', line 5

def columns
  @columns
end

#criteriaObject

Returns the value of attribute criteria.



5
6
7
# File 'lib/dynamics_crm/xml/query_expression.rb', line 5

def criteria
  @criteria
end

#entity_nameObject

Returns the value of attribute entity_name.



5
6
7
# File 'lib/dynamics_crm/xml/query_expression.rb', line 5

def entity_name
  @entity_name
end

#page_infoObject

Returns the value of attribute page_info.



5
6
7
# File 'lib/dynamics_crm/xml/query_expression.rb', line 5

def page_info
  @page_info
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
34
35
# File 'lib/dynamics_crm/xml/query_expression.rb', line 12

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

  column_set = columns.is_a?(ColumnSet) ? columns : ColumnSet.new(columns)

  xml = %(
      #{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 />
    )

  xml << page_info.to_xml if page_info

  if options[:exclude_root].nil?
    xml = %(<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

  xml
end