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
115 116 117 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 115 def all resolve_all_associations end |
#find_aggregations ⇒ Object
92 93 94 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 92 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
105 106 107 108 109 110 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 105 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.
86 87 88 89 90 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 86 def find_by_type(association_type) resolve_all_associations.select do |assoc| assoc.member_end_type == association_type end end |
#find_compositions ⇒ Object
96 97 98 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 96 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.
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 77 78 79 |
# File 'lib/lutaml/uml_repository/queries/association_query.rb', line 48 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.respond_to?(:associations) && klass.associations results.concat(klass.associations) end # Get associations from document level unless owned_only if !owned_only && document.respond_to?(:associations) && 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 |