Class: Enterprisifier::Schema::Elements::SchemaElement
- Inherits:
-
BaseElement
- Object
- BaseElement
- Enterprisifier::Schema::Elements::SchemaElement
- Defined in:
- lib/enterprisifier/schema/elements/schema.rb
Constant Summary collapse
- RegisterableElements =
%w[simpleType complexType group attributeGroup element attribute]
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#registries ⇒ Object
readonly
Returns the value of attribute registries.
Attributes inherited from BaseElement
#attributes, #children, #default_namespace, #namespaces, #parent, #text
Instance Method Summary collapse
- #default_registry ⇒ Object
-
#initialize(*args) ⇒ SchemaElement
constructor
A new instance of SchemaElement.
- #merge_schemas(other_schema, namespace = nil) ⇒ Object
- #update(element, state) ⇒ Object
- #xsd_namespace?(namespace_ref) ⇒ Boolean
Methods inherited from BaseElement
#add_child, #add_text, #annotation, #base, #documentation, #each_child, #has_child?, #has_children?, map_attribute, #name, #read_attribute, #ref, register, #registered_as, #root, #rootable?
Constructor Details
#initialize(*args) ⇒ SchemaElement
Returns a new instance of SchemaElement.
14 15 16 17 18 19 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 14 def initialize(*args) super @registries = {} set_default_namespace add_observer(self) end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 8 def path @path end |
#registries ⇒ Object (readonly)
Returns the value of attribute registries.
9 10 11 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 9 def registries @registries end |
Instance Method Details
#default_registry ⇒ Object
39 40 41 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 39 def default_registry registry_for(default_namespace) end |
#merge_schemas(other_schema, namespace = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 27 def merge_schemas(other_schema, namespace = nil) if namespace ns_def = @namespaces.rassoc(namespace) raise ArgumentError, "Namespace #{namespace} is not defined in this schema document." unless ns_def end other_schema.each_child { |child| add_child(child) } namespaces.concat(other_schema.namespaces).uniq! other_schema.registries.each do |ns,values| values.each { |key,elements| registry_for(ns)[key].reverse_merge!(elements) } end end |
#update(element, state) ⇒ Object
21 22 23 24 25 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 21 def update(element, state) return nil if element.default_namespace != default_namespace return nil unless state == :child_added && default_registry.has_key?(element.registered_as) register_element(element) end |
#xsd_namespace?(namespace_ref) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/enterprisifier/schema/elements/schema.rb', line 43 def xsd_namespace?(namespace_ref) namespaces.any? do |ref,url| ref == namespace_ref && url == XMLSchemaNameSpaceURI end end |