ea 0.6.159 → 0.6.161

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +13 -47
  3. data/lib/ea/export/xsd/class_mapping.rb +4 -4
  4. data/lib/ea/export/xsd/generator.rb +21 -12
  5. data/lib/ea/mdg/stereotype_alias_registry.rb +6 -6
  6. data/lib/ea/qea/database.rb +49 -0
  7. data/lib/ea/qea/factory/generalization_builder.rb +17 -17
  8. data/lib/ea/qea/infrastructure/table_reader.rb +26 -4
  9. data/lib/ea/qea/models/ea_datatype.rb +2 -2
  10. data/lib/ea/qea/models/ea_document.rb +2 -2
  11. data/lib/ea/qea/models/ea_script.rb +2 -2
  12. data/lib/ea/qea/services/configuration.rb +5 -7
  13. data/lib/ea/qea/services/database_loader.rb +31 -11
  14. data/lib/ea/qea/validation/formatters/text_formatter.rb +4 -4
  15. data/lib/ea/qea/validation/validation_engine.rb +4 -4
  16. data/lib/ea/qea/validation/validation_result.rb +4 -4
  17. data/lib/ea/qea/verification/comparison_result.rb +1 -1
  18. data/lib/ea/rules/general_attribute_mapping.rb +35 -0
  19. data/lib/ea/rules/namespacing.rb +27 -0
  20. data/lib/ea/rules.rb +10 -0
  21. data/lib/ea/sources/multiplicity.rb +41 -0
  22. data/lib/ea/sources/qea/relationship_builder.rb +6 -40
  23. data/lib/ea/sources/xmi/constraint_builder.rb +18 -18
  24. data/lib/ea/sources/xmi/diagram_builder/association_class_metadata.rb +50 -12
  25. data/lib/ea/sources/xmi/diagram_builder/connector_metadata.rb +59 -7
  26. data/lib/ea/sources/xmi/diagram_builder/font_settings.rb +2 -2
  27. data/lib/ea/sources/xmi/diagram_builder/umldi_edges/property_roles.rb +7 -5
  28. data/lib/ea/sources/xmi/diagram_builder/umldi_edges.rb +16 -10
  29. data/lib/ea/sources/xmi/extension_types.rb +2 -2
  30. data/lib/ea/sources/xmi/instance_builder.rb +6 -4
  31. data/lib/ea/sources/xmi/note_builder.rb +1 -1
  32. data/lib/ea/sources/xmi/reception_builder.rb +2 -2
  33. data/lib/ea/sources/xmi/relationship_builder.rb +6 -24
  34. data/lib/ea/sources/xmi/tag_builder.rb +2 -2
  35. data/lib/ea/sources/xmi/umldi_keyword_extractor.rb +2 -2
  36. data/lib/ea/sources.rb +1 -0
  37. data/lib/ea/svg/ea_emitter/document.rb +12 -1
  38. data/lib/ea/svg/ea_emitter/element/package_shape_renderer.rb +4 -4
  39. data/lib/ea/svg/ea_emitter/elements.rb +1 -1
  40. data/lib/ea/svg/parity/checker.rb +21 -10
  41. data/lib/ea/svg/parity/differ.rb +4 -2
  42. data/lib/ea/svg/parity/suite.rb +1 -1
  43. data/lib/ea/transformers/qea_to_xmi/transformer.rb +3 -7
  44. data/lib/ea/version.rb +1 -1
  45. data/lib/ea/xmi/liquid_drops/connector_drop.rb +2 -2
  46. data/lib/ea/xmi/parser.rb +39 -46
  47. data/lib/ea/xmi.rb +1 -1
  48. data/lib/ea/xml.rb +44 -0
  49. data/lib/ea.rb +2 -0
  50. metadata +23 -18
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -15,7 +15,7 @@ module Ea
15
15
  def grouped_by_owner
16
16
  return {} unless @xmi_path
17
17
 
18
- @grouped_by_owner ||= read_receptions(Nokogiri::XML(File.read(@xmi_path)))
18
+ @grouped_by_owner ||= read_receptions(Ea::Xml.parse_file(@xmi_path))
19
19
  end
20
20
 
21
21
  private
@@ -147,12 +147,12 @@ module Ea
147
147
  target_id: target.idref,
148
148
  source_role_name: source.role&.name,
149
149
  target_role_name: target.role&.name,
150
- source_multiplicity_lower: card_lower(source.type&.multiplicity),
151
- source_multiplicity_upper: card_upper(source.type&.multiplicity),
152
- target_multiplicity_lower: card_lower(target.type&.multiplicity),
153
- target_multiplicity_upper: card_upper(target.type&.multiplicity),
154
- source_multiplicity_raw: raw_card(source.type&.multiplicity),
155
- target_multiplicity_raw: raw_card(target.type&.multiplicity),
150
+ source_multiplicity_lower: Sources::Multiplicity.lower(source.type&.multiplicity),
151
+ source_multiplicity_upper: Sources::Multiplicity.upper(source.type&.multiplicity),
152
+ target_multiplicity_lower: Sources::Multiplicity.lower(target.type&.multiplicity),
153
+ target_multiplicity_upper: Sources::Multiplicity.upper(target.type&.multiplicity),
154
+ source_multiplicity_raw: Sources::Multiplicity.raw(source.type&.multiplicity),
155
+ target_multiplicity_raw: Sources::Multiplicity.raw(target.type&.multiplicity),
156
156
  source_aggregation: source_aggregation(connector),
157
157
  target_aggregation: target.type&.aggregation || "none",
158
158
  source_navigable: navigable?(element.id, :source),
@@ -190,24 +190,6 @@ module Ea
190
190
  }
191
191
  end
192
192
 
193
- def raw_card(cardinality)
194
- text = cardinality.to_s.strip
195
- text.empty? ? nil : text
196
- end
197
-
198
- def card_lower(cardinality)
199
- text = raw_card(cardinality)
200
- Integer(text.split("..").first, exception: false) if text
201
- end
202
-
203
- def card_upper(cardinality)
204
- text = raw_card(cardinality)
205
- return nil unless text
206
-
207
- upper = text.split("..").last
208
- upper == "*" ? -1 : Integer(upper, exception: false)
209
- end
210
-
211
193
  def generalization_args(element)
212
194
  # PackagedElement#generalization is a collection of
213
195
  # AssociationGeneralization rows. The "specific" (child)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -22,7 +22,7 @@ module Ea
22
22
  return {} if xmi_path.nil?
23
23
 
24
24
  @grouped ||= begin
25
- doc = Nokogiri::XML(File.read(xmi_path))
25
+ doc = Ea::Xml.parse_file(xmi_path)
26
26
  # <tags><tag/></tags> lives inside per-element <element>
27
27
  # blocks within <xmi:Extension>. The element itself is in
28
28
  # no XML namespace; match by local-name to be safe.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Sources
@@ -59,7 +59,7 @@ module Ea
59
59
  end
60
60
 
61
61
  def doc
62
- @doc ||= Nokogiri::XML(File.read(xmi_path))
62
+ @doc ||= Ea::Xml.parse_file(xmi_path)
63
63
  end
64
64
 
65
65
  def keywords_by_diagram
data/lib/ea/sources.rb CHANGED
@@ -9,6 +9,7 @@ module Ea
9
9
  # Adapters do not know about each other or about consumer
10
10
  # adapters (Ea::Spa, etc.).
11
11
  module Sources
12
+ autoload :Multiplicity, "ea/sources/multiplicity"
12
13
  autoload :Qea, "ea/sources/qea"
13
14
  autoload :Xmi, "ea/sources/xmi"
14
15
  end
@@ -130,12 +130,23 @@ module Ea
130
130
  end
131
131
 
132
132
  def render_image(image)
133
- svg = Ea::Image::EmfRenderer.render(image.bytes)
133
+ svg = Ea::Image::EmfRenderer.render(blob_for(image))
134
134
  return nil unless svg
135
135
 
136
136
  %(<g>#{svg}</g>)
137
137
  end
138
138
  private :render_image
139
+
140
+ # Blob bytes for one image row. Loaded rows carry their blob;
141
+ # blob-free loads (column-level exclusion at load time) hold
142
+ # metadata only, and the blob is fetched from the QEA file on
143
+ # demand via the database's reopen-per-fetch accessor.
144
+ #
145
+ # @param image [Ea::Qea::Models::EaImage]
146
+ # @return [String, nil] raw blob bytes, or nil when unavailable
147
+ def blob_for(image)
148
+ image.bytes || document.image_blob(image.image_id)
149
+ end
139
150
  end
140
151
  end
141
152
  end
@@ -76,7 +76,7 @@ module Ea
76
76
 
77
77
  def to_svg
78
78
  parts = [" #{body_polygon}", " #{tab_polygon}"]
79
- parts += header_text_blocks if has_label?
79
+ parts += header_text_blocks if label?
80
80
  %(<g style="#{group_style}">\n#{parts.join("\n")}\n</g>)
81
81
  end
82
82
 
@@ -85,11 +85,11 @@ module Ea
85
85
  attr_reader :bounds, :fill, :stroke, :stroke_width, :label,
86
86
  :stereotype, :family, :size, :size_unit, :text_fill
87
87
 
88
- def has_label?
88
+ def label?
89
89
  label && !label.empty?
90
90
  end
91
91
 
92
- def has_stereotype?
92
+ def stereotype?
93
93
  stereotype && !stereotype.empty?
94
94
  end
95
95
 
@@ -110,7 +110,7 @@ module Ea
110
110
 
111
111
  def header_text_blocks
112
112
  blocks = []
113
- if has_stereotype?
113
+ if stereotype?
114
114
  blocks << " #{text_at(label_x, stereotype_y, "«#{stereotype}»", weight: 0)}"
115
115
  blocks << " #{text_at(label_x, name_y, label, weight: 700)}"
116
116
  else
@@ -798,7 +798,7 @@ module Ea
798
798
  # actual content below (attributes, operations, literals, or
799
799
  # tagged values). Classes with only a header (no displayed
800
800
  # features) omit the divider entirely.
801
- def has_content_below_header?(attr_lines, op_lines, enum_literals, tagged_values = [])
801
+ def content_below_header?(attr_lines, op_lines, enum_literals, tagged_values = [])
802
802
  !attr_lines.empty? || !op_lines.empty? || enum_literals.any? || tagged_values.any?
803
803
  end
804
804
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
@@ -34,21 +34,25 @@ module Ea
34
34
  private
35
35
 
36
36
  def our_doc
37
- @our_doc ||= Nokogiri::XML(@ours)
37
+ @our_doc ||= Ea::Xml.parse(@ours)
38
38
  end
39
39
 
40
40
  def ref_doc
41
- @ref_doc ||= Nokogiri::XML(@reference)
41
+ @ref_doc ||= Ea::Xml.parse(@reference)
42
42
  end
43
43
 
44
+ # CSS is not reliable on moxml for namespaced documents
45
+ # (lutaml/moxml#582) — tag counting goes through xpath.
44
46
  def count_diff(selector)
45
- Diff.new(ours: our_doc.css(selector).size,
46
- reference: ref_doc.css(selector).size)
47
+ xpath = "//*[local-name()=\"#{selector}\"]"
48
+ Diff.new(ours: our_doc.xpath(xpath).size,
49
+ reference: ref_doc.xpath(xpath).size)
47
50
  end
48
51
 
49
52
  def top_level_group_diff
50
- Diff.new(ours: our_doc.css("svg > g").size,
51
- reference: ref_doc.css("svg > g").size)
53
+ xpath = "/*[local-name()=\"svg\"]/*[local-name()=\"g\"]"
54
+ Diff.new(ours: our_doc.xpath(xpath).size,
55
+ reference: ref_doc.xpath(xpath).size)
52
56
  end
53
57
 
54
58
  def font_family_match
@@ -65,7 +69,8 @@ module Ea
65
69
  end
66
70
 
67
71
  def font_style_histogram(doc, property)
68
- doc.css("text").each_with_object(Hash.new(0)) do |node, acc|
72
+ doc.xpath("//*[local-name()=\"text\"]")
73
+ .each_with_object(Hash.new(0)) do |node, acc|
69
74
  value = (node["style"] || "")[/#{Regexp.quote(property)}:([^;]+)/, 1]
70
75
  acc[value] += 1 if value
71
76
  end
@@ -76,14 +81,20 @@ module Ea
76
81
  end
77
82
 
78
83
  def text_overlap_ratio
79
- our_set = our_doc.css("text").map(&:text).map(&:strip).to_set
80
- ref_set = ref_doc.css("text").map(&:text).map(&:strip).to_set
84
+ our_set = text_set(our_doc)
85
+ ref_set = text_set(ref_doc)
81
86
  return 1.0 if our_set.empty? && ref_set.empty?
82
87
  return 0.0 if our_set.empty? || ref_set.empty?
83
88
 
84
89
  (our_set & ref_set).size.to_f / (our_set | ref_set).size.to_f
85
90
  end
86
91
 
92
+ def text_set(doc)
93
+ doc.xpath("//*[local-name()=\"text\"]").map do |node|
94
+ node.text.to_s.strip
95
+ end.to_set
96
+ end
97
+
87
98
  Diff = Struct.new(:ours, :reference, keyword_init: true) do
88
99
  def delta
89
100
  ours - reference
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
@@ -27,7 +27,9 @@ module Ea
27
27
  # Extracts the primitives consumed by both comparison reports.
28
28
  class PrimitiveParser
29
29
  def parse(svg)
30
- Nokogiri::XML(svg).css("g").flat_map do |group|
30
+ # xpath, not css — css is unreliable on moxml for
31
+ # namespaced documents (lutaml/moxml#582).
32
+ Ea::Xml.parse(svg).xpath('//*[local-name()="g"]').flat_map do |group|
31
33
  group.element_children.filter_map { |node| primitive(node, group["style"] || "") }
32
34
  end
33
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
 
5
5
  module Ea
6
6
  module Svg
@@ -472,7 +472,9 @@ module Ea
472
472
  # ---- Children of a classifier ------------------------------------
473
473
 
474
474
  def generalizations_for(obj)
475
- inheritance_connectors(obj, "Generalization")
475
+ Qea::Rules::Generalization
476
+ .connectors_from(obj.ea_object_id,
477
+ @context.connectors_for(obj.ea_object_id))
476
478
  .filter_map { |conn| build_generalization(conn) }
477
479
  end
478
480
 
@@ -749,12 +751,6 @@ module Ea
749
751
  value == "in" ? nil : value
750
752
  end
751
753
 
752
- def inheritance_connectors(obj, type)
753
- @context.connectors_for(obj.ea_object_id).select do |conn|
754
- conn.start_object_id == obj.ea_object_id && conn.connector_type == type
755
- end
756
- end
757
-
758
754
  # Realization connectors owned by this class — those where
759
755
  # this object is the source (client). Each emits an
760
756
  # `<interfaceRealization>`. Matched via the model predicate so
data/lib/ea/version.rb CHANGED
@@ -4,5 +4,5 @@ module Ea
4
4
  # Gem release version. Extracted to its own file so the
5
5
  # `gem-release` tool's `gem bump` can find and update it via the
6
6
  # standard `lib/<gem>/version.rb` convention.
7
- VERSION = "0.6.159"
7
+ VERSION = "0.6.161"
8
8
  end
@@ -45,8 +45,8 @@ module Ea
45
45
  end
46
46
 
47
47
  def recognized?
48
- !!@id_name_mapping[@model.source.idref] &&
49
- !!@id_name_mapping[@model.target.idref]
48
+ !@id_name_mapping[@model.source.idref].nil? &&
49
+ !@id_name_mapping[@model.target.idref].nil?
50
50
  end
51
51
  end
52
52
  end
data/lib/ea/xmi/parser.rb CHANGED
@@ -125,7 +125,7 @@ module Ea
125
125
  @pkg_elements_owned_attributes[id]
126
126
  end
127
127
 
128
- def find_subtype_of_from_generalization(id) # :CyclomaticComplexity,Metrics:MethodLength,Metrics:PerceivedComplexity
128
+ def find_subtype_of_from_generalization(id)
129
129
  matched_element = xmi_index.find_element(id)
130
130
  return unless matched_element&.links&.any?
131
131
 
@@ -381,7 +381,7 @@ module Ea
381
381
  end
382
382
  end
383
383
 
384
- def build_class(klass) # :CyclomaticComplexity,Metrics:PerceivedComplexity
384
+ def build_class(klass)
385
385
  ::Lutaml::Uml::UmlClass.new.tap do |k|
386
386
  k.xmi_id = klass.id
387
387
  k.name = klass.name
@@ -401,7 +401,7 @@ module Ea
401
401
  end
402
402
  end
403
403
 
404
- def build_enums(package) # :MethodLength,Metrics:AbcSize
404
+ def build_enums(package)
405
405
  return [] if package.packaged_element.nil?
406
406
 
407
407
  package.packaged_element
@@ -418,7 +418,7 @@ module Ea
418
418
  end
419
419
  end
420
420
 
421
- def build_data_types(package) # :AbcSize,Metrics:MethodLength
421
+ def build_data_types(package)
422
422
  return [] if package.packaged_element.nil?
423
423
 
424
424
  package.packaged_element
@@ -447,7 +447,7 @@ module Ea
447
447
  end
448
448
  end
449
449
 
450
- def build_diagrams(node_id) # :AbcSize,Metrics:MethodLength
450
+ def build_diagrams(node_id)
451
451
  return [] if @xmi_root_model.extension&.diagrams&.diagram.nil?
452
452
 
453
453
  diagram_lookup[node_id].map do |diagram|
@@ -465,14 +465,14 @@ module Ea
465
465
  end
466
466
  end
467
467
 
468
- def build_class_attributes(klass) # :AbcSize,Metrics:CyclomaticComplexity,Metrics:MethodLength
468
+ def build_class_attributes(klass)
469
469
  return [] if klass.owned_attribute.nil?
470
470
 
471
471
  all_props = klass.owned_attribute.select { |attr| attr.type?("uml:Property") }
472
472
  all_props.filter_map { |oa| build_attribute(oa) }
473
473
  end
474
474
 
475
- def build_attribute(owned_attr) # :AbcSize,Metrics:MethodLength
475
+ def build_attribute(owned_attr)
476
476
  uml_type = owned_attr.uml_type
477
477
  uml_type_idref = uml_type.idref if uml_type
478
478
 
@@ -496,7 +496,7 @@ module Ea
496
496
  end
497
497
  end
498
498
 
499
- def build_associations(xmi_id) # :AbcSize,Metrics:CyclomaticComplexity,Metrics:MethodLength,Metrics:PerceivedComplexity
499
+ def build_associations(xmi_id)
500
500
  matched_element = xmi_index&.find_element(xmi_id)
501
501
  return if !matched_element || !matched_element.links
502
502
 
@@ -510,7 +510,7 @@ module Ea
510
510
  end
511
511
  end
512
512
 
513
- def build_association(assoc, xmi_id) # :AbcSize,Metrics:CyclomaticComplexity,Metrics:MethodLength
513
+ def build_association(assoc, xmi_id)
514
514
  link_member = assoc.start == xmi_id ? "end" : "start"
515
515
  link_owner = link_member == "start" ? "end" : "start"
516
516
 
@@ -551,7 +551,7 @@ module Ea
551
551
  end
552
552
  end
553
553
 
554
- def build_operations(klass) # :MethodLength,Metrics:AbcSize
554
+ def build_operations(klass)
555
555
  return [] if klass.owned_operation.nil?
556
556
 
557
557
  klass.owned_operation.filter_map do |operation|
@@ -569,7 +569,7 @@ module Ea
569
569
  end
570
570
  end
571
571
 
572
- def build_constraints(klass_id) # :MethodLength,Metrics:AbcSize
572
+ def build_constraints(klass_id)
573
573
  connector_node = fetch_connector(klass_id)
574
574
  return [] if connector_node.nil?
575
575
 
@@ -587,7 +587,7 @@ module Ea
587
587
  end
588
588
  end
589
589
 
590
- def build_values(enum) # :MethodLength,Metrics:CyclomaticComplexity,Metrics:AbcSize
590
+ def build_values(enum)
591
591
  return [] if enum.owned_literal.nil?
592
592
 
593
593
  enum.owned_literal
@@ -607,7 +607,7 @@ module Ea
607
607
 
608
608
  # --- Generalization building ---
609
609
 
610
- def build_generalization(klass) # :AbcSize,Metrics:MethodLength,Metrics:CyclomaticComplexity,Metrics:PerceivedComplexity
610
+ def build_generalization(klass)
611
611
  uml_general_obj, next_general_node_id = get_uml_general(klass.id)
612
612
  return uml_general_obj unless next_general_node_id
613
613
 
@@ -626,21 +626,15 @@ module Ea
626
626
  uml_general_obj
627
627
  end
628
628
 
629
- def build_generalization_attributes(uml_general_obj) # :AbcSize,Metrics:MethodLength
629
+ def build_generalization_attributes(uml_general_obj)
630
630
  upper_klass = uml_general_obj.general_upper_klass
631
631
  gen_attrs = uml_general_obj.general_attributes
632
632
  gen_name = uml_general_obj.general_name
633
633
 
634
634
  gen_attrs&.each do |i|
635
- name_ns = case i.type_ns
636
- when "core", "gml"
637
- upper_klass
638
- else
639
- i.type_ns
640
- end
641
- name_ns = upper_klass if name_ns.nil?
642
-
643
- i.name_ns = name_ns
635
+ i.name_ns = Ea::Rules::Namespacing.resolve_name_ns(
636
+ i.type_ns, upper_klass
637
+ )
644
638
  i.gen_name = gen_name
645
639
  i.name = "" if i.name.nil?
646
640
  end
@@ -648,7 +642,7 @@ module Ea
648
642
  gen_attrs
649
643
  end
650
644
 
651
- def get_uml_general(general_id) # :AbcSize,Metrics:MethodLength
645
+ def get_uml_general(general_id)
652
646
  general_node = find_packaged_element_by_id(general_id)
653
647
  return [] unless general_node
654
648
 
@@ -704,22 +698,21 @@ module Ea
704
698
  uml_general.assoc_props = uml_general.attributes.select(&:association)
705
699
  end
706
700
 
707
- def get_uml_general_attributes(general_node) # :AbcSize,Metrics:MethodLength
701
+ def get_uml_general_attributes(general_node)
708
702
  attrs = build_class_attributes(general_node)
709
703
 
710
704
  attrs.map do |attr|
711
- ::Lutaml::Uml::GeneralAttribute.new.tap do |gen_attr|
712
- gen_attr.id = attr.id
713
- gen_attr.name = attr.name
714
- gen_attr.type = attr.type
715
- gen_attr.xmi_id = attr.xmi_id
716
- gen_attr.is_derived = !!attr.is_derived
717
- gen_attr.cardinality = attr.cardinality
718
- gen_attr.definition = get_uml_general_attribute_definition(attr)
719
- gen_attr.association = attr.association
720
- gen_attr.has_association = !!attr.association
721
- gen_attr.type_ns = attr.type_ns
722
- end
705
+ Ea::Rules::GeneralAttributeMapping.build(
706
+ id: attr.id,
707
+ name: attr.name,
708
+ type: attr.type,
709
+ xmi_id: attr.xmi_id,
710
+ cardinality: attr.cardinality,
711
+ definition: get_uml_general_attribute_definition(attr),
712
+ association: attr.association,
713
+ type_ns: attr.type_ns,
714
+ is_derived: attr.is_derived
715
+ )
723
716
  end
724
717
  end
725
718
 
@@ -742,7 +735,7 @@ module Ea
742
735
  uml_general_obj
743
736
  end
744
737
 
745
- def loop_general_item( # :MethodLength,Metrics:AbcSize,Metrics:PerceivedComplexity,Metrics:CyclomaticComplexity
738
+ def loop_general_item(
746
739
  general_item, level, inherited_props, inherited_assoc_props
747
740
  )
748
741
  gen_upper_klass = general_item.general_upper_klass
@@ -768,7 +761,7 @@ module Ea
768
761
  )
769
762
  end
770
763
 
771
- def build_assoc_generalizations(klass) # :AbcSize
764
+ def build_assoc_generalizations(klass)
772
765
  return [] if klass.generalization.nil? || klass.generalization.empty?
773
766
 
774
767
  klass.generalization.map do |gen|
@@ -795,7 +788,7 @@ module Ea
795
788
  lookup_entity_name(xmi_id) || connector_source_name(xmi_id)
796
789
  end
797
790
 
798
- def serialize_member_end(owner_xmi_id, link) # :MethodLength,Metrics:AbcSize,Metrics:CyclomaticComplexity
791
+ def serialize_member_end(owner_xmi_id, link)
799
792
  case link.name
800
793
  when "NoteLink"
801
794
  return
@@ -819,7 +812,7 @@ module Ea
819
812
  [member_end, member_end_type, xmi_id]
820
813
  end
821
814
 
822
- def member_end_name(xmi_id, source_or_target, link) # :MethodLength
815
+ def member_end_name(xmi_id, source_or_target, link)
823
816
  connector_label = connector_labels(xmi_id, source_or_target)
824
817
  entity_name = lookup_entity_name(xmi_id)
825
818
  connector_name = connector_name_by_source_or_target(xmi_id, source_or_target)
@@ -832,7 +825,7 @@ module Ea
832
825
  end
833
826
  end
834
827
 
835
- def serialize_member_type(owner_xmi_id, link, link_member_name) # :MethodLength,Metrics:AbcSize
828
+ def serialize_member_type(owner_xmi_id, link, link_member_name)
836
829
  member_end, member_end_type, xmi_id =
837
830
  serialize_member_end(owner_xmi_id, link)
838
831
 
@@ -883,7 +876,7 @@ module Ea
883
876
  assoc_connector.role ? assoc_connector.model.name : nil
884
877
  end
885
878
 
886
- def generalization_association(owner_xmi_id, link) # :MethodLength
879
+ def generalization_association(owner_xmi_id, link)
887
880
  member_end_type = "generalization"
888
881
  xmi_id = link.start
889
882
  source_or_target = :source
@@ -900,7 +893,7 @@ module Ea
900
893
 
901
894
  def fetch_owned_attribute_node(xmi_id)
902
895
  oa = xmi_index.find_owned_attrs_by_type(xmi_id)
903
- .find { |a| !!a.association }
896
+ .find { |a| !a.association.nil? }
904
897
 
905
898
  if oa
906
899
  cardinality = cardinality_min_max_value(
@@ -966,7 +959,7 @@ module Ea
966
959
  connector_lookup[[source_or_target.to_sym, xmi_id]]
967
960
  end
968
961
 
969
- def connector_name_by_source_or_target(xmi_id, source_or_target) # :AbcSize
962
+ def connector_name_by_source_or_target(xmi_id, source_or_target)
970
963
  node = connector_node_by_id(xmi_id, source_or_target)
971
964
  return node.name if node&.name
972
965
 
@@ -996,7 +989,7 @@ module Ea
996
989
  iterate_tree(items, model, type, method.to_sym)
997
990
  end
998
991
 
999
- def iterate_tree(result, node, type, children_method) # :AbcSize,Metrics:CyclomaticComplexity,Metrics:PerceivedComplexity
992
+ def iterate_tree(result, node, type, children_method)
1000
993
  result << node if type.nil? || node.type == type
1001
994
  return unless node.public_send(children_method)
1002
995
 
data/lib/ea/xmi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
3
+ require "moxml"
4
4
  require "xmi"
5
5
  require "liquid"
6
6
  require "cgi"
data/lib/ea/xml.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ea
4
+ # Shared XML parse entry for the gem's direct parses. Lenient by
5
+ # default — nokogiri/libxml2 parity — tolerating files whose bytes
6
+ # do not match UTF-8 (EA exports declare windows-1252 regularly and
7
+ # bundle raw CP1252 bytes alongside).
8
+ module Xml
9
+ DECLARED_ENCODING = /\A\s*<\?xml[^>]*encoding=["']([^"']+)["']/
10
+
11
+ module_function
12
+
13
+ # @param path [String] file path
14
+ # @return [Moxml::Wrappers::Document]
15
+ def parse_file(path)
16
+ parse(File.read(path))
17
+ end
18
+
19
+ # @param content [String] XML text
20
+ # @return [Moxml::Wrappers::Document]
21
+ def parse(content)
22
+ context = Moxml.new
23
+ context.config.strict_parsing = false
24
+ context.parse(normalize_encoding(content))
25
+ end
26
+
27
+ # libxml2 transcoded according to the XML declaration; moxml's
28
+ # parse validates UTF-8 strictly regardless of the declaration.
29
+ # Transcode declared non-UTF-8 content to UTF-8 and rewrite the
30
+ # declaration so downstream sees consistent text.
31
+ def normalize_encoding(content)
32
+ declared = content[DECLARED_ENCODING, 1]
33
+ return content if declared.nil? || declared.casecmp?("utf-8")
34
+
35
+ text = content.dup.force_encoding(declared).encode("UTF-8")
36
+ text.sub!(/\A(\s*<\?xml[^>]*encoding=["'])([^"']+)/) do
37
+ "#{Regexp.last_match(1)}UTF-8"
38
+ end
39
+ text
40
+ rescue StandardError
41
+ content.valid_encoding? ? content : content.scrub
42
+ end
43
+ end
44
+ end
data/lib/ea.rb CHANGED
@@ -9,6 +9,7 @@ module Ea
9
9
  class Error < StandardError; end
10
10
 
11
11
  autoload :Qea, "ea/qea"
12
+ autoload :Rules, "ea/rules"
12
13
  autoload :Model, "ea/model"
13
14
  autoload :Sources, "ea/sources"
14
15
  autoload :Spa, "ea/spa"
@@ -29,6 +30,7 @@ module Ea
29
30
  autoload :Lint, "ea/lint"
30
31
  autoload :Query, "ea/query"
31
32
  autoload :Ocl, "ea/ocl"
33
+ autoload :Xml, "ea/xml"
32
34
  autoload :XmlEscape, "ea/xml_escape"
33
35
  autoload :GuidFormat, "ea/guid_format"
34
36
  autoload :Rtf, "ea/rtf"