Class: Ea::Sources::Qea::ClassifierBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/sources/qea/classifier_builder.rb

Overview

Translates EA t_object rows (filtered to classifier types) into the appropriate Ea::Model::Classifier subclass. Uses ObjectClassifierMap for dispatch (OCP — new classifier kinds need no edit here).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, mdg_registry: nil) ⇒ ClassifierBuilder

Returns a new instance of ClassifierBuilder.



13
14
15
16
# File 'lib/ea/sources/qea/classifier_builder.rb', line 13

def initialize(database, mdg_registry: nil)
  @database = database
  @mdg_registry = mdg_registry
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



11
12
13
# File 'lib/ea/sources/qea/classifier_builder.rb', line 11

def database
  @database
end

#mdg_registryObject (readonly)

Returns the value of attribute mdg_registry.



11
12
13
# File 'lib/ea/sources/qea/classifier_builder.rb', line 11

def mdg_registry
  @mdg_registry
end

Instance Method Details

#build_allObject



18
19
20
21
22
23
24
# File 'lib/ea/sources/qea/classifier_builder.rb', line 18

def build_all
  classifiers = []
  each_classifier_object do |object|
    classifiers << build_one(object)
  end
  classifiers
end

#build_one(object) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ea/sources/qea/classifier_builder.rb', line 26

def build_one(object)
  klass = classifier_class_for(object)
  args = common_args(object)
  args.merge!(enumeration_args(object)) if klass == Ea::Model::Enumeration
  args.delete(:properties) if klass == Ea::Model::Enumeration
  klass.new(**args)
end

#classifier_class_for(object) ⇒ Object

EA's t_object.Object_Type selects the concrete classifier subclass, but a Class with the "enumeration" stereotype is rendered as an Enumeration (literals compartment, no visibility marker). Promote the model class when the stereotype says so.



39
40
41
42
43
44
45
# File 'lib/ea/sources/qea/classifier_builder.rb', line 39

def classifier_class_for(object)
  base = ObjectClassifierMap.class_for(object.object_type)
  return base unless base == Ea::Model::Klass
  return Ea::Model::Enumeration if enumeration_stereotype?(object)

  base
end

#enumeration_stereotype?(object) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/ea/sources/qea/classifier_builder.rb', line 47

def enumeration_stereotype?(object)
  stereotype = object.stereotype.to_s
  !stereotype.empty? && stereotype.downcase == "enumeration"
end

#properties_for(object) ⇒ Object

Resolves the classifier's full attribute list. Combines:

1. Own properties from t_attribute
2. Inherited properties from MDG-defined ancestor classes,
 when an mdg_registry is provided AND the classifier's
 applied stereotype maps to an MDG class.

Public so integration tests can drive the merge directly without stubbing the entire build_one pipeline.

When no mdg_registry is wired in, this returns just the own properties — preserving prior behavior.



63
64
65
66
67
68
69
70
71
72
# File 'lib/ea/sources/qea/classifier_builder.rb', line 63

def properties_for(object)
  own = PropertyBuilder.new(database).build_all_for(object)
  return own unless mdg_registry

  inherited = mdg_inherited_properties_for(object)
  return own if inherited.empty?

  own_names = own.to_set { |p| p.name.to_s }
  own + inherited.reject { |p| own_names.include?(p.name.to_s) }
end