Class: Mxrb::Compiler::MicroflowDocumentCompiler

Inherits:
Object
  • Object
show all
Includes:
ModelValues, RuntimeDataTypes
Defined in:
lib/mxrb/compiler/microflow_document_compiler.rb

Overview

Compiles microflow-family roots and delegates ordered graph nodes.

Constant Summary collapse

ROOT_TYPES =
%w[Microflows$Microflow Microflows$Nanoflow Microflows$Rule].freeze

Constants included from RuntimeDataTypes

RuntimeDataTypes::SCALARS

Instance Method Summary collapse

Constructor Details

#initialize(source, schema) ⇒ MicroflowDocumentCompiler

Returns a new instance of MicroflowDocumentCompiler.



14
15
16
17
18
# File 'lib/mxrb/compiler/microflow_document_compiler.rb', line 14

def initialize(source, schema)
  @schema = schema
  @nodes = MicroflowNodeCompiler.new(schema, source:)
  @role_map = project_role_map(source)
end

Instance Method Details

#compile(unit) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
# File 'lib/mxrb/compiler/microflow_document_compiler.rb', line 20

def compile(unit)
  source = unit.document
  raise CompilationError, "unsupported flow root #{source['$Type']}" unless ROOT_TYPES.include?(source['$Type'])

  @nodes.prepare(source)
  @schema.fields_for(source).to_h do |field|
    [field, root_value(source, field, unit.module_name)]
  end
end