Class: Mxrb::DomainDiagram::Document
- Inherits:
-
Object
- Object
- Mxrb::DomainDiagram::Document
- Defined in:
- lib/mxrb/domain_diagram.rb
Overview
Builds a framework-neutral JSON projection from arbitrary Mendix modules.
Instance Method Summary collapse
-
#initialize(path, modules: []) ⇒ Document
constructor
A new instance of Document.
- #to_h ⇒ Object
Constructor Details
#initialize(path, modules: []) ⇒ Document
Returns a new instance of Document.
25 26 27 28 |
# File 'lib/mxrb/domain_diagram.rb', line 25 def initialize(path, modules: []) @path = File.(path) @selected_modules = Array(modules).map(&:to_s) end |
Instance Method Details
#to_h ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mxrb/domain_diagram.rb', line 30 def to_h Model::Project.open(@path).then do |project| selected = project.modules unless @selected_modules.empty? unknown = @selected_modules.uniq - selected.map(&:name) raise ArgumentError, "unknown modules: #{unknown.join(', ')}" unless unknown.empty? selected = selected.select { @selected_modules.include?(_1.name) } end anchor_overrides = project.mpr.domain_diagram_anchors known = project.modules.each_with_object({}) do |mod, names| mod.entities.each do |entity| qualified = entity.qualified_name || "#{mod.name}.#{entity.name}" names[entity.id] = qualified names[qualified] = qualified end end { project: { name: project.name, mendix_version: project.mendix_version }, module_filter_applied: !@selected_modules.empty?, modules: selected.filter_map { module_payload(_1, known, anchor_overrides) } } ensure project&.close end end |