Class: Lutaml::Lml::ModelCompiler
- Inherits:
-
Object
- Object
- Lutaml::Lml::ModelCompiler
- Defined in:
- lib/lutaml/lml/model_compiler.rb
Defined Under Namespace
Classes: ValidationError
Constant Summary collapse
- TYPE_MAP =
{ "String" => :string, "Integer" => :integer, "Boolean" => :boolean, "Float" => :float, "Date" => :date, "date_time" => :date_time, "DateTime" => :date_time, "Time" => :time, "Uri" => :string, "Hash" => :hash, }.freeze
- UNBOUNDED_TOKENS =
Tokens that denote unbounded cardinality in LML attribute declarations. Anything else must parse as an Integer.
%w[* n N unbounded].freeze
Instance Method Summary collapse
- #compile(input) ⇒ Object
- #compiled_classes ⇒ Object
- #hydrate(input) ⇒ Object
-
#initialize(namespace: nil) ⇒ ModelCompiler
constructor
A new instance of ModelCompiler.
-
#validate(input, compiled: nil) ⇒ Object
Validate an instances document against compiled models.
Constructor Details
#initialize(namespace: nil) ⇒ ModelCompiler
Returns a new instance of ModelCompiler.
25 26 27 28 29 30 |
# File 'lib/lutaml/lml/model_compiler.rb', line 25 def initialize(namespace: nil) @namespace = namespace @compiled = {} @forward_refs = {} @enum_names = Set.new end |
Instance Method Details
#compile(input) ⇒ Object
32 33 34 35 36 |
# File 'lib/lutaml/lml/model_compiler.rb', line 32 def compile(input) doc = Pipeline.call(input, resolve: false) compile_document(doc) @compiled end |
#compiled_classes ⇒ Object
46 47 48 |
# File 'lib/lutaml/lml/model_compiler.rb', line 46 def compiled_classes @compiled end |
#hydrate(input) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/lutaml/lml/model_compiler.rb', line 38 def hydrate(input) doc = input.is_a?(Document) ? input : Pipeline.call(input, resolve: false) compile_document(doc) unless @compiled.any? return {} unless doc.instance hydrate_instance(doc.instance) end |
#validate(input, compiled: nil) ⇒ Object
Validate an instances document against compiled models.
Accepts the instances input as a String, IO, StringIO, or a
pre-parsed Document. If compiled: is supplied, that registry is
used; otherwise models are compiled from the same input (which
must therefore contain a models section).
Returns an array of validation error strings (empty if all pass).
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lutaml/lml/model_compiler.rb', line 58 def validate(input, compiled: nil) doc = input.is_a?(Document) ? input : Pipeline.call(input, resolve: false) if compiled @compiled = compiled else compile_document(doc) end errors = [] validate_instance(doc.instance, errors) if doc.instance errors end |