Class: Mxrb::Compiler::MicroflowNodeCompiler

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

Overview

rubocop:disable Metrics/AbcSize, Metrics/ClassLength, Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity Recursively compiles ordered objects nested inside microflow graphs.

Constant Summary collapse

FIELD_SOURCES =
{
  ['Microflows$BasicCodeActionParameterValue', 'ValueExpression'] => 'Argument',
  ['Microflows$CreateVariableAction', 'Type'] => 'VariableType',
  ['Microflows$MicroflowParameter', 'Type'] => 'VariableType',
  ['Microflows$MappingRequestHandling', 'ContentTypeRuntime'] => 'ContentType',
  ['Microflows$RetrieveSorting', 'AttributePath'] => 'AttributeRef',
  ['Microflows$RestCallAction', 'RequestTimeOutExpression'] => 'TimeOutExpression',
  ['Microflows$ResultHandling', 'VariableDataType'] => 'VariableType'
}.freeze
TYPE_DEFAULTS =
{
  'Microflows$NoCase' => { 'StringRepresentation' => '' }
}.freeze
RUNTIME_DERIVED_FIELDS =
{
  'Microflows$ActionActivity' => %w[Caption]
}.freeze
EDITORIAL_TYPES =
%w[Microflows$AnnotationFlow].freeze

Constants included from RuntimeDataTypes

RuntimeDataTypes::SCALARS

Instance Method Summary collapse

Constructor Details

#initialize(schema, source: nil) ⇒ MicroflowNodeCompiler

Returns a new instance of MicroflowNodeCompiler.



31
32
33
34
35
36
# File 'lib/mxrb/compiler/microflow_node_compiler.rb', line 31

def initialize(schema, source: nil)
  @schema = schema
  @database_connector = DatabaseConnectorActionCompiler.new(source) if source.respond_to?(:units)
  @associations = association_index(source)
  @variable_types = {}
end

Instance Method Details

#compile(value) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/mxrb/compiler/microflow_node_compiler.rb', line 48

def compile(value)
  case value
  when Hash then compile_hash(value)
  when Array then array(value).filter_map { compile(_1) }
  else value
  end
end

#prepare(flow) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/mxrb/compiler/microflow_node_compiler.rb', line 38

def prepare(flow)
  @variable_types = {}
  visit(flow) do |node|
    next unless node['$Type'] == 'Microflows$MicroflowParameter'

    entity = node.dig('VariableType', 'Entity').to_s
    @variable_types[node['Name'].to_s] = entity unless entity.empty?
  end
end