Class: Mxrb::Compiler::SourceModel
- Inherits:
-
Object
- Object
- Mxrb::Compiler::SourceModel
- Defined in:
- lib/mxrb/compiler/source_model.rb
Overview
Read-only indexed view of MPR units used by native materializers.
Defined Under Namespace
Classes: Unit
Constant Summary collapse
- CLIENT_TYPE =
/\A(?:Forms|JavaScriptActions|Menus|Navigation)\$|\AMicroflows\$Nanoflow\z/
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #client_reference?(qualified_name) ⇒ Boolean
- #document_index ⇒ Object
- #documents(type = nil) ⇒ Object
-
#initialize(path) ⇒ SourceModel
constructor
A new instance of SourceModel.
- #optimized_web_client? ⇒ Boolean
- #units_of(type) ⇒ Object
- #web_layout?(unit) ⇒ Boolean
- #web_page?(unit) ⇒ Boolean
Constructor Details
#initialize(path) ⇒ SourceModel
Returns a new instance of SourceModel.
14 15 16 17 |
# File 'lib/mxrb/compiler/source_model.rb', line 14 def initialize(path) @path = path read_units end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/mxrb/compiler/source_model.rb', line 10 def path @path end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
10 11 12 |
# File 'lib/mxrb/compiler/source_model.rb', line 10 def units @units end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
10 11 12 |
# File 'lib/mxrb/compiler/source_model.rb', line 10 def version @version end |
Class Method Details
.read(path) ⇒ Object
12 |
# File 'lib/mxrb/compiler/source_model.rb', line 12 def self.read(path) = new(File.(path)) |
Instance Method Details
#client_reference?(qualified_name) ⇒ Boolean
56 57 58 59 60 61 |
# File 'lib/mxrb/compiler/source_model.rb', line 56 def client_reference?(qualified_name) reference = /(?:\A|[^A-Za-z0-9_.])@#{Regexp.escape(qualified_name)}(?![A-Za-z0-9_.])/ units.any? do |unit| unit.document['$Type'].to_s.match?(CLIENT_TYPE) && deep_string_match?(unit.document, reference) end end |
#document_index ⇒ Object
29 30 31 32 33 |
# File 'lib/mxrb/compiler/source_model.rb', line 29 def document_index @document_index ||= {}.tap do |index| units.each { index_document(_1.document, index) } end.freeze end |
#documents(type = nil) ⇒ Object
19 20 21 22 |
# File 'lib/mxrb/compiler/source_model.rb', line 19 def documents(type = nil) selected = type ? units.select { _1.document['$Type'] == type } : units selected.map(&:document) end |
#optimized_web_client? ⇒ Boolean
50 51 52 53 54 |
# File 'lib/mxrb/compiler/source_model.rb', line 50 def optimized_web_client? settings = documents('Settings$ProjectSettings').first web = nested_values(settings).find { _1.is_a?(Hash) && _1['$Type'] == 'Forms$WebUIProjectSettingsPart' } web&.fetch('UseOptimizedClient', nil).to_s == 'Yes' end |
#units_of(type) ⇒ Object
24 25 26 27 |
# File 'lib/mxrb/compiler/source_model.rb', line 24 def units_of(type) @units_by_type ||= units.group_by { _1.document['$Type'] }.transform_values(&:freeze).freeze @units_by_type.fetch(type, EMPTY_UNITS) end |
#web_layout?(unit) ⇒ Boolean
45 46 47 48 |
# File 'lib/mxrb/compiler/source_model.rb', line 45 def web_layout?(unit) unit.document['Excluded'] != true && unit.document.dig('Content', '$Type') == 'Forms$WebLayoutContent' end |
#web_page?(unit) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/mxrb/compiler/source_model.rb', line 35 def web_page?(unit) return false if unit.document['Excluded'] == true layout_name = unit.document.dig('FormCall', 'Form').to_s layout = units_of('Forms$Layout').find do |candidate| "#{candidate.module_name}.#{candidate.document['Name']}" == layout_name end layout.nil? || layout.document.dig('Content', '$Type') != 'Forms$NativeLayoutContent' end |