Class: Safrano::ComplexType
- Inherits:
-
Object
- Object
- Safrano::ComplexType
- 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
-
.namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
.props ⇒ Object
readonly
Returns the value of attribute props.
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
-
.add_metadata_rexml(schema) ⇒ Object
add metadata xml to the passed REXML schema object.
-
.default_template ⇒ Object
needed for nested json output this is a simpler version of model_ext#output_template.
- .output_template ⇒ Object
- .return_as_collection_descriptor ⇒ Object
- .return_as_instance_descriptor ⇒ Object
- .type_name ⇒ Object
Instance Method Summary collapse
- #casted_values ⇒ Object
-
#initialize ⇒ ComplexType
constructor
A new instance of ComplexType.
- #metadata_h ⇒ Object
- #odata_h ⇒ Object
- #type_name ⇒ Object
Constructor Details
#initialize ⇒ ComplexType
Returns a new instance of ComplexType.
236 237 238 |
# File 'lib/odata/complex_type.rb', line 236 def initialize @values = {} end |
Class Attribute Details
.namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
195 196 197 |
# File 'lib/odata/complex_type.rb', line 195 def namespace @namespace end |
.props ⇒ Object (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
#values ⇒ Object (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_template ⇒ Object
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 } = {} @props.each do |prop, kl| [prop] = kl.default_template if kl.respond_to? :default_template end template[:expand_e] = template end |
.output_template ⇒ Object
228 229 230 |
# File 'lib/odata/complex_type.rb', line 228 def self.output_template default_template end |
.return_as_collection_descriptor ⇒ Object
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_descriptor ⇒ Object
255 256 257 |
# File 'lib/odata/complex_type.rb', line 255 def self.return_as_instance_descriptor FunctionImport::ResultDefinition.asComplexType(self) end |
.type_name ⇒ Object
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_values ⇒ Object
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_h ⇒ Object
206 207 208 |
# File 'lib/odata/complex_type.rb', line 206 def { type: type_name } end |
#odata_h ⇒ Object
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_name ⇒ Object
202 203 204 |
# File 'lib/odata/complex_type.rb', line 202 def type_name self.class.type_name end |