Class: OdataDuty::SchemaBuilder::EntityType

Inherits:
ComplexType
  • Object
show all
Defined in:
lib/odata_duty/schema_builder/entity_type.rb

Instance Attribute Summary collapse

Attributes inherited from ComplexType

#object, #od_context

Instance Method Summary collapse

Methods inherited from ComplexType

__metadata, properties, property

Constructor Details

#initialize(**kwargs) ⇒ EntityType

Returns a new instance of EntityType.



8
9
10
11
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 8

def initialize(**kwargs)
  super
  @property_refs = []
end

Instance Attribute Details

#property_refsObject (readonly)

Returns the value of attribute property_refs.



6
7
8
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 6

def property_refs
  @property_refs
end

Instance Method Details

#int_mapper(context, selected:) ⇒ Object



31
32
33
34
35
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 31

def int_mapper(context, selected:)
  MapperBuilder.build(self, selected: selected) do |result, obj|
    result['@odata.id'] = "#{context.current.fetch('odata_url_base')}(#{obj.id})"
  end
end

#integer_property_ref?Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 43

def integer_property_ref?
  @property_ref_raw_type ||= property_refs.first.raw_type
  @property_ref_raw_type == EdmInt64
end

#mapper(context, selected:) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 22

def mapper(context, selected:)
  context.current['odata_url_base'] ||= context.od_full_url(context.endpoint.url)
  if integer_property_ref?
    int_mapper(context, selected: selected)
  else
    string_mapper(context, selected: selected)
  end
end

#property_ref(*args, **kwargs) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 13

def property_ref(*args, **kwargs)
  kwargs[:mutability] = :computed unless kwargs.key?(:mutability) || kwargs.key?(:computed)
  property(*args, nullable: false, **kwargs).tap do |property|
    raise 'Multiple Property Reference not yet supported' if property_refs.size.positive?

    property_refs << property
  end
end

#string_mapper(context, selected:) ⇒ Object



37
38
39
40
41
# File 'lib/odata_duty/schema_builder/entity_type.rb', line 37

def string_mapper(context, selected:)
  MapperBuilder.build(self, selected: selected) do |result, obj|
    result['@odata.id'] = "#{context.current.fetch('odata_url_base')}('#{obj.id}')"
  end
end