Class: Mxrb::Compiler::LegacyCustomWidgetCompiler

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

Overview

Serializes schema-described Mendix 6/7 custom widgets to their Dojo client contract. rubocop:disable Metrics

Constant Summary collapse

SUPPORTED_TYPES =
%w[
  Attribute Boolean Decimal Entity EntityConstraint Enumeration Form Image Integer
  Microflow String System TranslatableString Object
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, widget, language:) ⇒ LegacyCustomWidgetCompiler

Returns a new instance of LegacyCustomWidgetCompiler.



19
20
21
22
23
24
25
26
# File 'lib/mxrb/compiler/legacy_custom_widget_compiler.rb', line 19

def initialize(source, widget, language:)
  @source = source
  @widget = widget
  @language = language
  @widget_type = widget['Type'] || {}
  @widget_id = @widget_type['WidgetId'].to_s
  @schema_index = schema_index(@widget_type)
end

Instance Attribute Details

#widget_idObject (readonly)

Returns the value of attribute widget_id.



17
18
19
# File 'lib/mxrb/compiler/legacy_custom_widget_compiler.rb', line 17

def widget_id
  @widget_id
end

Instance Method Details

#properties_hashObject



35
36
37
38
39
40
# File 'lib/mxrb/compiler/legacy_custom_widget_compiler.rb', line 35

def properties_hash
  properties(@widget['Object']).to_h do |property|
    schema = property_schema(property)
    [schema['PropertyKey'].to_s, compile_value(schema.dig('ValueType', 'Type'), property['Value'])]
  end
end

#supported?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/mxrb/compiler/legacy_custom_widget_compiler.rb', line 28

def supported?
  !widget_id.empty? && package_module? && properties(@widget['Object']).all? do |property|
    type = property_type(property)
    SUPPORTED_TYPES.include?(type) && supported_value?(type, property['Value'])
  end
end