class Safrano::ComplexType

a generic Struct like ruby's standard Struct, but implemented with a @values Hash, similar to Sequel models and with added OData functionality

Constants

EMPTYH
METAK
TYPEK

Attributes

values[R]

Public Class Methods

add_metadata_rexml(schema) click to toggle source

add metadata xml to the passed REXML schema object

# File lib/odata/complex_type.rb, line 262
def self.add_metadata_rexml(schema)
  ctty = schema.add_element('ComplexType', 'Name' => to_s)

  # with their properties
  @props.each do |prop, rbtype|
    attrs = { 'Name' => prop.to_s,
              'Type' => rbtype.type_name }
    ctty.add_element('Property', attrs)
  end
  ctty
end
default_template() click to toggle source

needed for nested json output this is a simpler version of model_ext#output_template

# File lib/odata/complex_type.rb, line 212
def self.default_template
  template = {}
  expand_e = {}

  template[:all_values] = EMPTYH
  @props.each { |prop, kl|
    if kl.respond_to? :default_template
      expand_e[prop] = kl.default_template
    end
  }
  template[:expand_e] = expand_e
  template
end
namespace() click to toggle source
# File lib/odata/complex_type.rb, line 189
def self.namespace
  @namespace
end
new() click to toggle source
# File lib/odata/complex_type.rb, line 234
def initialize
  @values = {}
end
output_template() click to toggle source
# File lib/odata/complex_type.rb, line 226
def self.output_template
  default_template
end
props() click to toggle source
# File lib/odata/complex_type.rb, line 193
def self.props
  @props
end
return_as_collection_descriptor() click to toggle source
# File lib/odata/complex_type.rb, line 253
def self.return_as_collection_descriptor
  FunctionImport::ResultDefinition.asComplexTypeColl(self)
end
return_as_instance_descriptor() click to toggle source
# File lib/odata/complex_type.rb, line 257
def self.return_as_instance_descriptor
  FunctionImport::ResultDefinition.asComplexType(self)
end
type_name() click to toggle source
# File lib/odata/complex_type.rb, line 230
def self.type_name
  @namespace ? "#{@namespace}.#{self.to_s}" : self.to_s
end

Public Instance Methods

casted_values() click to toggle source
# File lib/odata/complex_type.rb, line 205
def casted_values
  # MVP... TODO: handle time mappings like in Entity models
  values
end
metadata_h() click to toggle source
# File lib/odata/complex_type.rb, line 201
def metadata_h
  {   type: type_name }
end
odata_h() click to toggle source
# File lib/odata/complex_type.rb, line 240
def odata_h
  ret = { METAK => { TYPEK => self.class.type_name } }

  @values.each { |k, v|
    ret[k] = if v.respond_to? :odata_h
               v.odata_h
             else
               v
             end
  }
  ret
end
type_name() click to toggle source
# File lib/odata/complex_type.rb, line 197
def type_name
  self.class.type_name
end