class OData4::Schema::ComplexType

ComplexTypes are used in OData4 to either encapsulate richer data types for use as Entity properties. ComplexTypes are composed of properties the same way that Entities are and, so, the interface for working with the various properties of a ComplexType mimics that of Entities.

Public Class Methods

new(type_definition, schema) click to toggle source

Creates a new ComplexType based on the supplied options. @param type_xml [Nokogiri::XML::Element] @param service [OData4::Service]

# File lib/odata4/schema/complex_type.rb, line 11
def initialize(type_definition, schema)
  @type_definition = type_definition
  @schema          = schema
end

Public Instance Methods

name() click to toggle source

The name of the ComplexType @return [String]

# File lib/odata4/schema/complex_type.rb, line 18
def name
  @name ||= type_definition.attributes['Name'].value
end
namespace() click to toggle source

Returns the namespace this ComplexType belongs to. @return [String]

# File lib/odata4/schema/complex_type.rb, line 30
def namespace
  @namespace ||= service.namespace
end
properties() click to toggle source

Returns this ComplexType's properties. @return [Hash<String, OData4::Property>]

# File lib/odata4/schema/complex_type.rb, line 36
def properties
  @properties ||= collect_properties
end
property_class() click to toggle source

Returns the property class that implements this `ComplexType`. @return [Class < OData4::Properties::Complex]

# File lib/odata4/schema/complex_type.rb, line 48
def property_class
  @property_class ||= lambda { |type, complex_type|
    klass = Class.new ::OData4::Properties::Complex
    klass.send(:define_method, :type) { type }
    klass.send(:define_method, :complex_type) { complex_type }
    klass
  }.call(type, self)
end
property_names() click to toggle source

Returns a list of this ComplexType's property names. @return [Array<String>]

# File lib/odata4/schema/complex_type.rb, line 42
def property_names
  @property_names ||= properties.keys
end
type() click to toggle source

Returns the namespaced type for the ComplexType. @return [String]

# File lib/odata4/schema/complex_type.rb, line 24
def type
  "#{namespace}.#{name}"
end

Private Instance Methods

collect_properties() click to toggle source
# File lib/odata4/schema/complex_type.rb, line 71
def collect_properties
  Hash[type_definition.xpath('./Property').map do |property_xml|
    property_name, property = schema.send(:process_property_from_xml, property_xml)
    [property_name, property]
  end]
end
schema() click to toggle source
# File lib/odata4/schema/complex_type.rb, line 59
def schema
  @schema
end
service() click to toggle source
# File lib/odata4/schema/complex_type.rb, line 63
def service
  @schema.service
end
type_definition() click to toggle source
# File lib/odata4/schema/complex_type.rb, line 67
def type_definition
  @type_definition
end