Class: Lutaml::UmlRepository::Queries::AssociationQuery
- Defined in:
- lib/lutaml/uml_repository/queries/association_query.rb
Overview
Query service for association operations.
Provides methods to find associations related to classes. Associations can be owned by classes or defined at the document level.
Instance Method Summary collapse
-
#all ⇒ Array<Lutaml::Uml::Association>
Retrieve all associations in the document.
- #find_aggregations ⇒ Object
-
#find_between_classes(owner_end_xmi_id, member_end_xmi_id) ⇒ Array<Lutaml::Uml::Association>
Find associations between two classes.
-
#find_by_type(association_type) ⇒ Array<Lutaml::Uml::Association>
Find associations by their type.
- #find_compositions ⇒ Object
-
#find_for_class(class_or_qname, options = {}) ⇒ Array<Lutaml::Uml::Association>
Find associations for a specific class.
Methods inherited from BaseQuery
Constructor Details
This class inherits a constructor from Lutaml::UmlRepository::Queries::BaseQuery
Instance Method Details
#all ⇒ Array<Lutaml::Uml::Association>
Retrieve all associations in the document
112 113 114 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 112 def all resolve_all_associations end |
#find_aggregations ⇒ Object
89 90 91 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 89 def find_aggregations find_by_type("aggregation") end |
#find_between_classes(owner_end_xmi_id, member_end_xmi_id) ⇒ Array<Lutaml::Uml::Association>
Find associations between two classes
102 103 104 105 106 107 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 102 def find_between_classes(owner_end_xmi_id, member_end_xmi_id) resolve_all_associations.select do |assoc| assoc.owner_end_xmi_id == owner_end_xmi_id && assoc.member_end_xmi_id == member_end_xmi_id end end |
#find_by_type(association_type) ⇒ Array<Lutaml::Uml::Association>
Find associations by their type.
83 84 85 86 87 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 83 def find_by_type(association_type) resolve_all_associations.select do |assoc| assoc.member_end_type == association_type end end |
#find_compositions ⇒ Object
93 94 95 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 93 def find_compositions find_by_type("composition") end |
#find_for_class(class_or_qname, options = {}) ⇒ Array<Lutaml::Uml::Association>
Find associations for a specific class.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 45 def find_for_class(class_or_qname, = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity owned_only = [:owned_only] || false navigable_only = [:navigable_only] || false direction = [:direction] || :both klass = resolve_class(class_or_qname) return [] unless klass class_name = klass.name results = [] # Get owned associations from the class itself if (klass.is_a?(Lutaml::Uml::Class) || klass.is_a?(Lutaml::Uml::DataType)) && klass.associations results.concat(klass.associations) end # Get associations from document level unless owned_only if !owned_only && document.is_a?(Lutaml::Uml::Document) && document.associations document_associations = document.associations.select do |assoc| match_association?(assoc, class_name, direction) end results.concat(document_associations) end # Filter navigable if requested if navigable_only results.select! { |assoc| navigable?(assoc) } end results.uniq end |