Class: Lutaml::XMI::KlassDrop

Inherits:
Liquid::Drop
  • Object
show all
Includes:
Parsers::XMIBase
Defined in:
lib/lutaml/xmi/liquid_drops/klass_drop.rb

Instance Method Summary collapse

Methods included from Parsers::XMIBase

included, #set_xmi_model

Constructor Details

#initialize(model, guidance = nil, options = {}) ⇒ KlassDrop

rubocop:disable Lint/MissingSuper,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 8

def initialize(model, guidance = nil, options = {}) # rubocop:disable Lint/MissingSuper,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  @model = model
  @guidance = guidance
  @options = options
  @xmi_root_model = options[:xmi_root_model]
  @id_name_mapping = options[:id_name_mapping]

  @package = model&.packaged_element&.find do |e|
    e.type?("uml:Package")
  end

  @owned_attributes = model&.owned_attribute&.select do |attr|
    attr.type?("uml:Property")
  end

  if @xmi_root_model
    @matched_element = @xmi_root_model&.extension&.elements&.element&.find do |e| # rubocop:disable Layout/LineLength,Style/SafeNavigationChainLength
      e.idref == @model.id
    end

    @dependencies = select_dependencies_by_supplier(@model.id)

    @inheritance_ids = @matched_element&.links&.map do |link|
      link.generalization.select do |gen|
        gen.end == @model.id
      end.map(&:id)
    end&.flatten&.compact || []
  end

  if guidance
    @klass_guidance = guidance["classes"].find do |klass|
      klass["name"] == name || klass["name"] == absolute_path
    end
  end
end

Instance Method Details

#absolute_pathObject



52
53
54
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 52

def absolute_path
  "#{@options[:absolute_path]}::#{name}"
end

#associationsObject

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 100

def associations # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
  return if !@matched_element || !@matched_element.links

  links = []
  @matched_element.links.each do |link|
    links << link.association if link.association.any?
    links << link.generalization if link.generalization.any?
  end

  links.flatten.compact.map do |assoc|
    link_member = assoc.start == xmi_id ? "end" : "start"
    link_owner_name = link_member == "start" ? "end" : "start"

    member_end, member_end_type, member_end_cardinality,
      member_end_attribute_name, member_end_xmi_id =
      serialize_member_type(xmi_id, assoc, link_member)

    owner_end = serialize_owned_type(xmi_id, assoc, link_owner_name)

    if member_end && ((member_end_type != "aggregation") ||
      (member_end_type == "aggregation" && member_end_attribute_name))

      doc_node_name = (link_member == "start" ? "source" : "target")
      definition = fetch_definition_node_value(assoc.id, doc_node_name)

      ::Lutaml::XMI::AssociationDrop.new(
        xmi_id: assoc.id,
        member_end: member_end,
        member_end_type: member_end_type,
        member_end_cardinality: member_end_cardinality,
        member_end_attribute_name: member_end_attribute_name,
        member_end_xmi_id: member_end_xmi_id,
        owner_end: owner_end,
        owner_end_xmi_id: xmi_id,
        definition: definition,
        options: @options,
      )
    end
  end.compact
end

#attributesObject



72
73
74
75
76
77
78
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 72

def attributes
  @owned_attributes.map do |owned_attr|
    if @options[:with_assoc] || owned_attr.association.nil?
      ::Lutaml::XMI::AttributeDrop.new(owned_attr, @options)
    end
  end.compact
end

#constraintsObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 149

def constraints
  connector_node = fetch_connector(@model.id)
  return unless connector_node

  # In ea-xmi-2.5.1, constraints are moved to source/target under
  # connectors
  constraints = %i[source target].map do |st|
    connector_node.send(st).constraints.constraint
  end.flatten

  constraints.map do |constraint|
    ::Lutaml::XMI::ConstraintDrop.new(constraint)
  end
end

#definitionObject



183
184
185
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 183

def definition
  doc_node_attribute_value(@model.id, "documentation")
end

#dependenciesObject



86
87
88
89
90
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 86

def dependencies
  @dependencies.map do |dependency|
    ::Lutaml::XMI::DependencyDrop.new(dependency, @options)
  end.compact
end

#generalizationObject



164
165
166
167
168
169
170
171
172
173
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 164

def generalization
  if @options[:with_gen] && @model.type?("uml:Class")
    generalization = serialize_generalization(@model)
    return {} if generalization.nil?

    ::Lutaml::XMI::GeneralizationDrop.new(
      generalization, @klass_guidance, @options
    )
  end
end

#has_guidance?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 175

def has_guidance?
  !!@klass_guidance
end

#inheritancesObject



92
93
94
95
96
97
98
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 92

def inheritances
  @inheritance_ids.map do |inheritance_id|
    # ::Lutaml::XMI::InheritanceDrop.new(dependency, @options)
    connector = fetch_connector(inheritance_id)
    ::Lutaml::XMI::ConnectorDrop.new(connector, @options)
  end.compact
end

#is_abstractObject

rubocop:disable Naming/PredicateName,Naming/PredicatePrefix



179
180
181
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 179

def is_abstract # rubocop:disable Naming/PredicateName,Naming/PredicatePrefix
  doc_node_attribute_value(@model.id, "isAbstract")
end

#nameObject



48
49
50
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 48

def name
  @model.name
end

#operationsObject



141
142
143
144
145
146
147
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 141

def operations
  @model.owned_operation.map do |operation|
    if operation.association.nil?
      ::Lutaml::XMI::OperationDrop.new(operation)
    end
  end.compact
end

#owned_attributesObject



80
81
82
83
84
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 80

def owned_attributes
  @owned_attributes.map do |owned_attr|
    ::Lutaml::XMI::AttributeDrop.new(owned_attr, @options)
  end.compact
end

#packageObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 56

def package
  ::Lutaml::XMI::PackageDrop.new(
    @package,
    @guidance,
    @options.merge(
      {
        absolute_path: "#{@options[:absolute_path]}::#{name}",
      },
    ),
  )
end

#stereotypeObject



187
188
189
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 187

def stereotype
  doc_node_attribute_value(@model.id, "stereotype")
end

#typeObject



68
69
70
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 68

def type
  @model.type.split(":").last
end

#xmi_idObject



44
45
46
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 44

def xmi_id
  @model.id
end