Class: OData4::Schema
- Inherits:
-
Object
- Object
- OData4::Schema
- Defined in:
- lib/odata4/schema.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
The schema’s metadata (i.e its XML definition).
-
#service ⇒ Object
readonly
The schema’s parent service.
Instance Method Summary collapse
-
#actions ⇒ Array<String>
Returns a list of actions defined by the schema.
-
#complex_types ⇒ Hash<String, OData4::ComplexType>
Returns a list of ‘ComplexType`s defined by the schema.
-
#entity_types ⇒ Array<String>
Returns a list of entities defined by the schema.
-
#enum_types ⇒ Hash<String, OData4::EnumType>
Returns a list of EnumTypes defined by the schema.
-
#functions ⇒ Array<String>
Returns a list of functions defined by the schema.
-
#get_property_type(entity_name, property_name) ⇒ String
Get the property type for an entity from metadata.
-
#initialize(schema_definition, service) ⇒ Schema
constructor
Creates a new schema.
-
#namespace ⇒ String
Returns the schema’s ‘Namespace` attribute (mandatory).
-
#navigation_properties ⇒ Hash<Hash<OData4::NavigationProperty>>
Returns a hash for finding an association through an entity type’s defined NavigationProperty elements.
-
#primary_key_for(entity_name) ⇒ String
Get the primary key for the supplied Entity.
-
#properties_for_entity(entity_name) ⇒ Hash
private
Get the list of properties and their various options for the supplied Entity name.
-
#type_definitions ⇒ Array<String>
Returns a list of type definitions defined by the schema.
Constructor Details
#initialize(schema_definition, service) ⇒ Schema
Creates a new schema.
12 13 14 15 |
# File 'lib/odata4/schema.rb', line 12 def initialize(schema_definition, service) @metadata = schema_definition @service = service end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
The schema’s metadata (i.e its XML definition)
6 7 8 |
# File 'lib/odata4/schema.rb', line 6 def @metadata end |
#service ⇒ Object (readonly)
The schema’s parent service
4 5 6 |
# File 'lib/odata4/schema.rb', line 4 def service @service end |
Instance Method Details
#actions ⇒ Array<String>
Returns a list of actions defined by the schema.
25 26 27 28 29 |
# File 'lib/odata4/schema.rb', line 25 def actions @actions ||= .xpath('//Action').map do |action| action.attributes['Name'].value end end |
#complex_types ⇒ Hash<String, OData4::ComplexType>
Returns a list of ‘ComplexType`s defined by the schema.
41 42 43 44 45 46 47 48 |
# File 'lib/odata4/schema.rb', line 41 def complex_types @complex_types ||= .xpath('//ComplexType').map do |entity| [ entity.attributes['Name'].value, ::OData4::ComplexType.new(entity, self) ] end.to_h end |
#entity_types ⇒ Array<String>
Returns a list of entities defined by the schema.
33 34 35 36 37 |
# File 'lib/odata4/schema.rb', line 33 def entity_types @entity_types ||= .xpath('//EntityType').map do |entity| entity.attributes['Name'].value end end |
#enum_types ⇒ Hash<String, OData4::EnumType>
Returns a list of EnumTypes defined by the schema.
52 53 54 55 56 57 58 59 |
# File 'lib/odata4/schema.rb', line 52 def enum_types @enum_types ||= .xpath('//EnumType').map do |entity| [ entity.attributes['Name'].value, ::OData4::EnumType.new(entity, self) ] end.to_h end |
#functions ⇒ Array<String>
Returns a list of functions defined by the schema.
63 64 65 66 67 |
# File 'lib/odata4/schema.rb', line 63 def functions @functions ||= .xpath('//Function').map do |function| function.attributes['Name'].value end end |
#get_property_type(entity_name, property_name) ⇒ String
Get the property type for an entity from metadata.
99 100 101 |
# File 'lib/odata4/schema.rb', line 99 def get_property_type(entity_name, property_name) .xpath("//EntityType[@Name='#{entity_name}']/Property[@Name='#{property_name}']").first.attributes['Type'].value end |
#namespace ⇒ String
Returns the schema’s ‘Namespace` attribute (mandatory).
19 20 21 |
# File 'lib/odata4/schema.rb', line 19 def namespace @namespace ||= .attributes['Namespace'].value end |
#navigation_properties ⇒ Hash<Hash<OData4::NavigationProperty>>
Returns a hash for finding an association through an entity type’s defined NavigationProperty elements.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/odata4/schema.rb', line 80 def @navigation_properties ||= .xpath('//EntityType').map do |entity_type_def| [ entity_type_def.attributes['Name'].value, entity_type_def.xpath('./NavigationProperty').map do |nav_property_def| [ nav_property_def.attributes['Name'].value, ::OData4::NavigationProperty.build(nav_property_def) ] end.to_h ] end.to_h end |
#primary_key_for(entity_name) ⇒ String
Get the primary key for the supplied Entity.
107 108 109 |
# File 'lib/odata4/schema.rb', line 107 def primary_key_for(entity_name) .xpath("//EntityType[@Name='#{entity_name}']/Key/PropertyRef").first.attributes['Name'].value end |
#properties_for_entity(entity_name) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the list of properties and their various options for the supplied Entity name.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/odata4/schema.rb', line 116 def properties_for_entity(entity_name) type_definition = .xpath("//EntityType[@Name='#{entity_name}']").first raise ArgumentError, "Unknown EntityType: #{entity_name}" if type_definition.nil? properties_to_return = {} type_definition.xpath('./Property').each do |property_xml| property_name, property = process_property_from_xml(property_xml) properties_to_return[property_name] = property end properties_to_return end |
#type_definitions ⇒ Array<String>
Returns a list of type definitions defined by the schema.
71 72 73 74 75 |
# File 'lib/odata4/schema.rb', line 71 def type_definitions @typedefs ||= .xpath('//TypeDefinition').map do |typedef| typedef.attributes['Name'].value end end |