Class: Frodo::Schema
- Inherits:
-
Object
- Object
- Frodo::Schema
- Defined in:
- lib/frodo/schema.rb,
lib/frodo/schema/enum_type.rb,
lib/frodo/schema/complex_type.rb
Defined Under Namespace
Classes: ComplexType, EnumType
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.
-
#alias ⇒ String
Returns the schema’s ‘Alias` attribute.
-
#complex_types ⇒ Hash<String, Frodo::Schema::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, Frodo::Schema::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, navigation_properties = nil) ⇒ Schema
constructor
Creates a new schema.
-
#namespace ⇒ String
Returns the schema’s ‘Namespace` attribute (mandatory).
-
#navigation_properties ⇒ Hash<Hash<Frodo::NavigationProperty>>
Returns a hash for finding an association through an entity type’s defined NavigationProperty elements.
-
#navigation_properties_for_entity(entity_name) ⇒ Hash
private
Get the list of navigation properties and their various options for the supplied Entity name.
-
#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.
-
#referential_constraints_for_entity(entity_name) ⇒ Object
Returns a hash for finding the associated read-only value property for a given navigation property.
-
#type_definitions ⇒ Array<String>
Returns a list of type definitions defined by the schema.
Constructor Details
#initialize(schema_definition, service, navigation_properties = nil) ⇒ Schema
Creates a new schema.
15 16 17 18 19 |
# File 'lib/frodo/schema.rb', line 15 def initialize(schema_definition, service, =nil) @metadata = schema_definition @service = service @navigation_properties = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
The schema’s metadata (i.e its XML definition)
9 10 11 |
# File 'lib/frodo/schema.rb', line 9 def @metadata end |
#service ⇒ Object (readonly)
The schema’s parent service
7 8 9 |
# File 'lib/frodo/schema.rb', line 7 def service @service end |
Instance Method Details
#actions ⇒ Array<String>
Returns a list of actions defined by the schema.
35 36 37 38 39 |
# File 'lib/frodo/schema.rb', line 35 def actions @actions ||= .xpath('//Action').map do |action| action.attributes['Name'].value end end |
#alias ⇒ String
Returns the schema’s ‘Alias` attribute.
29 30 31 |
# File 'lib/frodo/schema.rb', line 29 def alias @alias ||= .attributes['Alias']&.value end |
#complex_types ⇒ Hash<String, Frodo::Schema::ComplexType>
Returns a list of ‘ComplexType`s defined by the schema.
51 52 53 54 55 56 57 58 |
# File 'lib/frodo/schema.rb', line 51 def complex_types @complex_types ||= .xpath('//ComplexType').map do |entity| [ entity.attributes['Name'].value, ComplexType.new(entity, self) ] end.to_h end |
#entity_types ⇒ Array<String>
Returns a list of entities defined by the schema.
43 44 45 46 47 |
# File 'lib/frodo/schema.rb', line 43 def entity_types @entity_types ||= .xpath('//EntityType').map do |entity| entity.attributes['Name'].value end end |
#enum_types ⇒ Hash<String, Frodo::Schema::EnumType>
Returns a list of EnumTypes defined by the schema.
62 63 64 65 66 67 68 69 |
# File 'lib/frodo/schema.rb', line 62 def enum_types @enum_types ||= .xpath('//EnumType').map do |entity| [ entity.attributes['Name'].value, EnumType.new(entity, self) ] end.to_h end |
#functions ⇒ Array<String>
Returns a list of functions defined by the schema.
73 74 75 76 77 |
# File 'lib/frodo/schema.rb', line 73 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.
141 142 143 |
# File 'lib/frodo/schema.rb', line 141 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).
23 24 25 |
# File 'lib/frodo/schema.rb', line 23 def namespace @namespace ||= .attributes['Namespace'].value end |
#navigation_properties ⇒ Hash<Hash<Frodo::NavigationProperty>>
Returns a hash for finding an association through an entity type’s defined NavigationProperty elements.
90 91 92 93 94 95 96 97 98 |
# File 'lib/frodo/schema.rb', line 90 def @navigation_properties ||= .xpath('//EntityType').map do |entity_type_def| entity_name = entity_type_def.attributes['Name'].value [ entity_name, (entity_name) ] end.to_h end |
#navigation_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 navigation properties and their various options for the supplied Entity name.
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/frodo/schema.rb', line 105 def (entity_name) type_definition = get_type_definition_for_entity_name(entity_name) parent_properties = recurse_on_parent_type(type_definition) properties_to_return = type_definition.xpath('./NavigationProperty').map do |nav_property_def| [ nav_property_def.attributes['Name'].value, ::Frodo::NavigationProperty.build(nav_property_def) ] end.to_h parent_properties.merge!(properties_to_return) end |
#primary_key_for(entity_name) ⇒ String
Get the primary key for the supplied Entity.
149 150 151 |
# File 'lib/frodo/schema.rb', line 149 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.
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/frodo/schema.rb', line 158 def properties_for_entity(entity_name) type_definition = get_type_definition_for_entity_name(entity_name) properties_to_return = {} parent_properties = recurse_on_parent_type(type_definition) type_definition.xpath('./Property').each do |property_xml| property_name, property = process_property_from_xml(property_xml) properties_to_return[property_name] = property end parent_properties.merge!(properties_to_return) end |
#referential_constraints_for_entity(entity_name) ⇒ Object
Returns a hash for finding the associated read-only value property for a given navigation property
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/frodo/schema.rb', line 122 def referential_constraints_for_entity(entity_name) type_definition = get_type_definition_for_entity_name(entity_name) parent_refcons = recurse_on_parent_type(type_definition) refcons_to_return = type_definition.xpath('./NavigationProperty[ReferentialConstraint]').map do |nav_property_def| [ nav_property_def.attributes['Name'].value, nav_property_def.xpath('./ReferentialConstraint').first.attributes['Property'].value ] end.to_h parent_refcons.merge!(refcons_to_return) end |
#type_definitions ⇒ Array<String>
Returns a list of type definitions defined by the schema.
81 82 83 84 85 |
# File 'lib/frodo/schema.rb', line 81 def type_definitions @typedefs ||= .xpath('//TypeDefinition').map do |typedef| typedef.attributes['Name'].value end end |