Module: Lutaml::Model::Schema::XmlCompiler
- Extended by:
- XmlCompiler
- Included in:
- XmlCompiler
- Defined in:
- lib/lutaml/model/schema/xml_compiler.rb,
lib/lutaml/model/schema/xml_compiler/spec_builder.rb,
lib/lutaml/model/schema/xml_compiler/element_order.rb,
lib/lutaml/model/schema/xml_compiler/registry_generator.rb,
lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb,
lib/lutaml/model/schema/xml_compiler/supported_data_types.rb,
lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb,
lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb
Defined Under Namespace
Modules: ElementOrder, SupportedDataTypes Classes: RegistryGenerator, SpecBuilder
Constant Summary collapse
- ELEMENT_ORDER_IGNORABLE =
%w[import include].freeze
- XML_ADAPTER_NOT_SET_MESSAGE =
<<~MSG Nokogiri is not set as XML Adapter. Make sure Nokogiri is installed and set as XML Adapter eg. execute: gem install nokogiri require 'lutaml/xml' Lutaml::Model::Config.xml_adapter = :nokogiri MSG
- XML_DEFINED_ATTRIBUTES =
{ "id" => "Lutaml::Xml::W3c::XmlIdType", "lang" => "Lutaml::Xml::W3c::XmlLangType", "space" => "Lutaml::Xml::W3c::XmlSpaceType", "base" => "Lutaml::Xml::W3c::XmlBaseType", }.freeze
- XML_NAMESPACE_URI =
"http://www.w3.org/XML/1998/namespace"
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
The SpecBuilder instance set up by
as_models.
Instance Method Summary collapse
Instance Attribute Details
#builder ⇒ Object (readonly)
The SpecBuilder instance set up by as_models. Exposed so
tests can introspect the walked Definitions::* hashes (e.g.
XmlCompiler.builder.attributes["id"]) without re-walking.
38 39 40 |
# File 'lib/lutaml/model/schema/xml_compiler.rb', line 38 def builder @builder end |
Instance Method Details
#as_models(schema, options: {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lutaml/model/schema/xml_compiler.rb', line 68 def as_models(schema, options: {}) unless Config.xml_adapter.name.end_with?("NokogiriAdapter") raise Error, XML_ADAPTER_NOT_SET_MESSAGE end parsed_schema = Lutaml::Xml::Schema::Xsd.parse( schema, location: [:location] ) schemas = Array(parsed_schema) @builder = SpecBuilder.new @builder.populate_default_attributes @builder.collect_namespaces(schemas, ) @builder.walk_schemas(schemas) end |
#to_models(schema, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lutaml/model/schema/xml_compiler.rb', line 40 def to_models(schema, = {}) as_models(schema, options: ) [:indent] = [:indent] ? [:indent].to_i : 2 unless .key?(:module_namespace) output_dir = .fetch(:output_dir, "lutaml_models_#{Time.now.to_i}") [:module_namespace] = File.basename(output_dir).split("_").map(&:capitalize).join end [:register_id] ||= :default if [:module_namespace] @builder.add_supported_types @builder.finalize_required_files! output = build_output() if [:create_files] dir = .fetch(:output_dir, "lutaml_models_#{Time.now.to_i}") FileWriter.write(output, dir, registry_generator: RegistryGenerator) true else ClassLoader.load(output, registry_generator: RegistryGenerator) if [:load_classes] output.sources end end |