Class: Lutaml::UmlRepository::StaticSite::Serializers::Base

Inherits:
Object
  • Object
show all
Includes:
Lutaml::Uml::ModelHelpers
Defined in:
lib/lutaml/uml_repository/static_site/serializers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Lutaml::Uml::ModelHelpers

#class_type_for, #extract_package_path, #format_cardinality, #format_definition, #normalize_stereotypes, #package_path_for, #parse_cardinality, #qualified_name_for

Constructor Details

#initialize(repository, id_generator, options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 12

def initialize(repository, id_generator, options = {})
  @repository = repository
  @id_generator = id_generator
  @options = options
end

Instance Attribute Details

#id_generatorObject (readonly)

Returns the value of attribute id_generator.



10
11
12
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 10

def id_generator
  @id_generator
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 10

def options
  @options
end

#repositoryObject (readonly)

Returns the value of attribute repository.



10
11
12
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 10

def repository
  @repository
end

Instance Method Details

#class_lookupObject



18
19
20
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 18

def class_lookup
  @class_lookup ||= ClassLookupIndex.new(@repository.classes_index)
end

#find_assoc_by_id(assoc_id) ⇒ Object



29
30
31
32
33
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 29

def find_assoc_by_id(assoc_id)
  @repository.associations_index.find do |a|
    @id_generator.association_id(a) == assoc_id
  end
end

#find_class_associations(klass) ⇒ Object



22
23
24
25
26
27
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 22

def find_class_associations(klass)
  associations = @repository.associations_of(klass)
  associations.map { |assoc| @id_generator.association_id(assoc) }
rescue StandardError
  []
end

#package_diagrams(package) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 45

def package_diagrams(package)
  return [] unless @options[:include_diagrams]

  package.diagrams || []
rescue StandardError => e
  warn "Error getting diagrams for #{package.name}: #{e.message}"
  []
end

#resolve_assoc_role(assoc, xmi_id) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 35

def resolve_assoc_role(assoc, xmi_id)
  if assoc.owner_end_xmi_id == xmi_id
    assoc.owner_end_attribute_name || assoc.owner_end || ""
  elsif assoc.member_end_xmi_id == xmi_id
    assoc.member_end_attribute_name || assoc.member_end || ""
  else
    ""
  end
end

#serialize_attribute(attribute, owner, _id) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/lutaml/uml_repository/static_site/serializers/base.rb', line 54

def serialize_attribute(attribute, owner, _id)
  Models::SpaAttribute.from_uml(
    attribute, owner,
    id_generator: @id_generator,
    definition: format_definition(attribute.definition, @options),
    stereotypes: normalize_stereotypes(attribute.stereotype)
  )
end