Class: Lutaml::Xmi::LiquidDrops::KlassDrop

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

Instance Method Summary collapse

Constructor Details

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

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



7
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
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 7

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

  if @xmi_root_model
    @clients_dependencies = @lookup.select_dependencies_by_supplier(@model.xmi_id)
    @suppliers_dependencies = @lookup.select_dependencies_by_client(@model.xmi_id)

    matched_element = @lookup.find_matched_element(@model.xmi_id)
    @inheritance_ids = matched_element&.links&.map do |link|
      link.generalization.select do |gen|
        gen.end == @model.xmi_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



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 42

def absolute_path
  absolute_path_arr = [@model.name]
  e = @lookup.find_upper_level_packaged_element(@model.xmi_id)
  absolute_path_arr << e.name if e

  while e
    e = @lookup.find_upper_level_packaged_element(e.id)
    absolute_path_arr << e.name if e
  end

  absolute_path_arr << "::#{@xmi_root_model.model.name}"
  absolute_path_arr.reverse.join("::")
end

#associationsObject



117
118
119
120
121
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 117

def associations
  @model.associations.filter_map do |assoc|
    ::Lutaml::Xmi::LiquidDrops::AssociationDrop.new(assoc, @options)
  end
end

#attributesObject



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

def attributes
  @model.attributes.filter_map do |owned_attr|
    if @options[:with_assoc] || owned_attr.association.nil?
      ::Lutaml::Xmi::LiquidDrops::AttributeDrop.new(owned_attr,
                                                    @options)
    end
  end
end

#clients_dependenciesObject



104
105
106
107
108
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 104

def clients_dependencies
  @clients_dependencies.filter_map do |dependency|
    ::Lutaml::Xmi::LiquidDrops::DependencyDrop.new(dependency, @options)
  end
end

#constraintsObject



129
130
131
132
133
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 129

def constraints
  @model.constraints.map do |constraint|
    ::Lutaml::Xmi::LiquidDrops::ConstraintDrop.new(constraint)
  end
end

#definitionObject



163
164
165
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 163

def definition
  @model.definition
end

#generalizationObject



135
136
137
138
139
140
141
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 135

def generalization
  if @options[:with_gen] && @model.generalization
    ::Lutaml::Xmi::LiquidDrops::GeneralizationDrop.new(
      @model.generalization, @klass_guidance, @options
    )
  end
end

#has_guidance?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 155

def has_guidance?
  !!@klass_guidance
end

#inheritancesObject



110
111
112
113
114
115
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 110

def inheritances
  @inheritance_ids.filter_map do |inheritance_id|
    connector = @lookup.fetch_connector(inheritance_id)
    ::Lutaml::Xmi::LiquidDrops::ConnectorDrop.new(connector, @options)
  end
end

#is_abstractObject

rubocop:disable Naming/PredicateName,Naming/PredicatePrefix



159
160
161
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 159

def is_abstract # rubocop:disable Naming/PredicateName,Naming/PredicatePrefix
  @model.is_abstract
end

#nameObject



38
39
40
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 38

def name
  @model.name
end

#operationsObject



123
124
125
126
127
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 123

def operations
  @model.operations.map do |operation|
    ::Lutaml::Xmi::LiquidDrops::OperationDrop.new(operation)
  end
end

#owned_attributesObject



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

def owned_attributes
  @model.attributes.filter_map do |owned_attr|
    ::Lutaml::Xmi::LiquidDrops::AttributeDrop.new(owned_attr, @options)
  end
end

#packageObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 56

def package
  nested_pkg = @lookup.find_packaged_element_by_id(@model.xmi_id)
  return unless nested_pkg

  xmi_pkg = nested_pkg.packaged_element&.find do |e|
    e.type?("uml:Package")
  end
  return unless xmi_pkg

  uml_pkg = ::Lutaml::Uml::Package.new
  uml_pkg.xmi_id = xmi_pkg.id
  uml_pkg.name = @lookup.get_package_name(xmi_pkg)
  ::Lutaml::Xmi::LiquidDrops::PackageDrop.new(
    uml_pkg,
    @guidance,
    @options.merge(
      {
        absolute_path: "#{@options[:absolute_path]}::#{name}",
      },
    ),
  )
end

#stereotypeObject



167
168
169
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 167

def stereotype
  @model.stereotype&.first
end

#subtype_ofObject



150
151
152
153
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 150

def subtype_of
  @lookup.find_subtype_of_from_generalization(@model.xmi_id) ||
    @lookup.find_subtype_of_from_owned_attribute_type(@model.xmi_id)
end

#suppliers_dependenciesObject



98
99
100
101
102
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 98

def suppliers_dependencies
  @suppliers_dependencies.filter_map do |dependency|
    ::Lutaml::Xmi::LiquidDrops::DependencyDrop.new(dependency, @options)
  end
end

#typeObject



79
80
81
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 79

def type
  @model.type
end

#upper_packaged_elementObject



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

def upper_packaged_element
  if @options[:with_gen]
    e = @lookup.find_upper_level_packaged_element(@model.xmi_id)
    e&.name
  end
end

#xmi_idObject



34
35
36
# File 'lib/lutaml/xmi/liquid_drops/klass_drop.rb', line 34

def xmi_id
  @model.xmi_id
end