class Lutaml::UmlRepository::QueryDSL::Conditions::PackageCondition
filtered = condition.apply(classes)
condition = PackageCondition.new(“ModelRoot::i-UR”, recursive: true)
@example Filter by package and descendants
filtered = condition.apply(classes)
“ModelRoot::i-UR”, recursive: false)
condition = PackageCondition.new(
@example Filter by exact package
recursive (descendant) matching.
Filters results based on package path, with support for
Package-based condition for filtering by package membership
def apply(results)
-
(Array)- Objects in the specified package
Parameters:
-
results(Array) -- The collection to filter
def apply(results) results.select do |obj| matches_package?(obj) end end
def coerce_package_path(path)
def coerce_package_path(path) return nil unless path path.is_a?(PackagePath) ? path : PackagePath.new(path) rescue ArgumentError nil end
def extract_package_path(obj)
-
(PackagePath, nil)- The object's package path
Parameters:
-
obj(Object) -- The object to extract path from
def extract_package_path(obj) return nil unless serializable_with_path?(obj) coerce_package_path(obj.package_path) end
def initialize(package_path, recursive: false)
-
recursive(Boolean) -- Whether to include descendants -
package_path(String, PackagePath) --
def initialize(package_path, recursive: false) super() @package_path = if package_path.is_a?(PackagePath) package_path else PackagePath.new(package_path) end @recursive = recursive end
def matches_package?(obj)
-
(Boolean)- true if object is in target package
Parameters:
-
obj(Object) -- The object to check
def matches_package?(obj) obj_package_path = extract_package_path(obj) return false unless obj_package_path if @recursive obj_package_path.starts_with?(@package_path) else obj_package_path == @package_path end end
def serializable_with_path?(obj)
def serializable_with_path?(obj) obj.is_a?(Lutaml::Model::Serializable) && obj.class.attributes&.key?(:package_path) end