Class: Mxrb::Compiler::NavigationDocumentCompiler

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

Overview

Compiles server-visible navigation profiles while preserving Runtime widget inventories.

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ NavigationDocumentCompiler

Returns a new instance of NavigationDocumentCompiler.



9
10
11
# File 'lib/mxrb/compiler/navigation_document_compiler.rb', line 9

def initialize(schema)
  @schema = schema
end

Instance Method Details

#compile(unit) ⇒ Object

rubocop:disable Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mxrb/compiler/navigation_document_compiler.rb', line 13

def compile(unit) # rubocop:disable Metrics/MethodLength
  source = unit.document
  existing = @schema.counterpart(source) || {}
  @schema.fields_for(source).to_h do |field|
    value = if field == 'Profiles'
              array(source['Profiles']).map { profile(_1) }
            elsif %w[$ID $Type].include?(field)
              source[field]
            else
              existing.fetch(field, source.fetch(field, []))
            end
    [field, value]
  end
end