Class: Safrano::ComplexType

Inherits:
Object
  • Object
show all
Defined in:
lib/odata/complex_type.rb

Overview

a generic Struct like ruby’s standard Struct, but implemented with a with added OData functionality

Constant Summary collapse

EMPTYH =
{}.freeze
METAK =
'__metadata'
TYPEK =
'type'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeComplexType

Returns a new instance of ComplexType.



236
237
238
# File 'lib/odata/complex_type.rb', line 236

def initialize
  @values = {}
end

Class Attribute Details

.namespaceObject (readonly)

Returns the value of attribute namespace.



195
196
197
# File 'lib/odata/complex_type.rb', line 195

def namespace
  @namespace
end

.propsObject (readonly)

Returns the value of attribute props.



199
200
201
# File 'lib/odata/complex_type.rb', line 199

def props
  @props
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



189
190
191
# File 'lib/odata/complex_type.rb', line 189

def values
  @values
end

Class Method Details

.add_metadata_rexml(schema) ⇒ Object

add metadata xml to the passed REXML schema object



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/odata/complex_type.rb', line 260

def self.(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_templateObject

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



217
218
219
220
221
222
223
224
225
226
# File 'lib/odata/complex_type.rb', line 217

def self.default_template
  template = { meta: EMPTYH, all_values: EMPTYH }
  expand_e = {}

  @props.each do |prop, kl|
    expand_e[prop] = kl.default_template if kl.respond_to? :default_template
  end
  template[:expand_e] = expand_e
  template
end

.output_templateObject



228
229
230
# File 'lib/odata/complex_type.rb', line 228

def self.output_template
  default_template
end

.return_as_collection_descriptorObject



251
252
253
# File 'lib/odata/complex_type.rb', line 251

def self.return_as_collection_descriptor
  FunctionImport::ResultDefinition.asComplexTypeColl(self)
end

.return_as_instance_descriptorObject



255
256
257
# File 'lib/odata/complex_type.rb', line 255

def self.return_as_instance_descriptor
  FunctionImport::ResultDefinition.asComplexType(self)
end

.type_nameObject



232
233
234
# File 'lib/odata/complex_type.rb', line 232

def self.type_name
  namespace ? "#{namespace}.#{self}" : to_s
end

Instance Method Details

#casted_valuesObject



210
211
212
213
# File 'lib/odata/complex_type.rb', line 210

def casted_values
  # MVP... TODO: handle time mappings like in Entity models
  values
end

#metadata_hObject



206
207
208
# File 'lib/odata/complex_type.rb', line 206

def 
  { type: type_name }
end

#odata_hObject



242
243
244
245
246
247
248
249
# File 'lib/odata/complex_type.rb', line 242

def odata_h
  ret = { METAK => { TYPEK => self.class.type_name } }

  @values.each do |key, val|
    ret[key] = val.respond_to?(:odata_h) ? val.odata_h : val
  end
  ret
end

#type_nameObject



202
203
204
# File 'lib/odata/complex_type.rb', line 202

def type_name
  self.class.type_name
end