Class: Mxrb::Compiler::WebListDataSource

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

Overview

Resolves React list data sources and safely lowers unusable simple connector reads to XPath. rubocop:disable Metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, widget) ⇒ WebListDataSource

Returns a new instance of WebListDataSource.



12
13
14
15
16
17
18
19
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 12

def initialize(source, widget)
  @source = source
  @widget = widget
  resolve_sources
  resolve_flows
  resolve_entity
  @xpath_constraint = @xpath&.fetch('XPathConstraint', '').to_s
end

Instance Attribute Details

#association_pathObject (readonly)

Returns the value of attribute association_path.



10
11
12
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 10

def association_path
  @association_path
end

#entityObject (readonly)

Returns the value of attribute entity.



10
11
12
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 10

def entity
  @entity
end

#microflow_nameObject (readonly)

Returns the value of attribute microflow_name.



10
11
12
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 10

def microflow_name
  @microflow_name
end

#nanoflow_nameObject (readonly)

Returns the value of attribute nanoflow_name.



10
11
12
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 10

def nanoflow_name
  @nanoflow_name
end

#xpath_constraintObject (readonly)

Returns the value of attribute xpath_constraint.



10
11
12
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 10

def xpath_constraint
  @xpath_constraint
end

Instance Method Details

#association?Boolean

Returns:

  • (Boolean)


58
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 58

def association? = !@association_source.nil? && !association_path.empty? && !entity.empty?

#flow_name(source, key) ⇒ Object



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

def flow_name(source, key)
  source&.dig("#{key}Settings", key).to_s.then do |name|
    name.empty? ? source&.fetch(key, '').to_s : name
  end
end

#microflow?Boolean

Returns:

  • (Boolean)


59
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 59

def microflow? = !@microflow_source.nil? && !microflow_name.empty? && !@flow.nil?

#nanoflow?Boolean

Returns:

  • (Boolean)


60
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 60

def nanoflow? = !@nanoflow_source.nil? && !nanoflow_name.empty? && !@nanoflow.nil?

#resolve_entityObject



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

def resolve_entity
  @entity = [
    entity_ref_destination(@xpath&.fetch('EntityRef', nil)),
    entity_ref_destination(@association_source&.fetch('EntityRef', nil)),
    @flow&.document&.dig('MicroflowReturnType', 'Entity'),
    @nanoflow&.document&.dig('MicroflowReturnType', 'Entity')
  ].map(&:to_s).find { !_1.empty? }.to_s
end

#resolve_flowsObject



42
43
44
45
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 42

def resolve_flows
  @flow = qualified_unit('Microflows$Microflow', microflow_name) unless microflow_name.empty?
  @nanoflow = qualified_unit('Microflows$Nanoflow', nanoflow_name) unless nanoflow_name.empty?
end

#resolve_sourcesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 21

def resolve_sources
  direct = widget['DataSource'] if widget.is_a?(Hash)
  @xpath = direct if database_source?(direct)
  @xpath ||= nested(widget, 'CustomWidgets$CustomWidgetXPathSource').first
  @association_source = direct if direct&.fetch('$Type', nil) == 'Forms$AssociationSource'
  @association_source ||= nested(widget, 'Forms$AssociationSource').first
  @microflow_source = direct if direct&.fetch('$Type', nil) == 'Forms$MicroflowSource'
  @microflow_source ||= nested(widget, 'Forms$MicroflowSource').first
  @nanoflow_source = direct if direct&.fetch('$Type', nil) == 'Forms$NanoflowSource'
  @nanoflow_source ||= nested(widget, 'Forms$NanoflowSource').first
  @microflow_name = flow_name(@microflow_source, 'Microflow')
  @nanoflow_name = @nanoflow_source&.fetch('Nanoflow', '').to_s
  @association_path = entity_ref_path(@association_source&.fetch('EntityRef', nil))
end

#supported?Boolean

Returns:

  • (Boolean)


56
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 56

def supported? = xpath? || association? || microflow? || nanoflow?

#xpath?Boolean

Returns:

  • (Boolean)


57
# File 'lib/mxrb/compiler/web_list_data_source.rb', line 57

def xpath? = !@xpath.nil? || connector_fallback?