Coverage for src/jsoncrack_for_sphinx/search/search_policy.py: 100%
11 statements
« prev ^ index » next coverage.py v7.10.0, created at 2025-07-24 22:26 +0000
« prev ^ index » next coverage.py v7.10.0, created at 2025-07-24 22:26 +0000
1"""
2Search policy configuration for schema files.
3"""
5from typing import Optional
7from ..utils.types import PathSeparator
10class SearchPolicy:
11 """Schema file search policy configuration."""
13 def __init__(
14 self,
15 include_package_name: bool = False,
16 include_path_to_file: bool = True,
17 path_to_file_separator: PathSeparator = PathSeparator.DOT,
18 path_to_class_separator: PathSeparator = PathSeparator.DOT,
19 custom_patterns: Optional[list] = None,
20 ):
21 """
22 Configure how schema files are searched.
24 Args:
25 include_package_name: Whether to include package name in search
26 patterns
27 include_path_to_file: Whether to include intermediate path
28 components (e.g., endpoints.catalog)
29 path_to_file_separator: How to separate path components in file
30 names
31 path_to_class_separator: How to separate class/method components
32 custom_patterns: Additional custom patterns to try (optional)
34 Examples:
35 For "perekrestok_api.endpoints.catalog.ProductService.similar":
37 SearchPolicy(False, True, PathSeparator.DOT, PathSeparator.DOT):
38 → "ProductService.similar.schema.json"
39 → "endpoints.catalog.ProductService.similar.schema.json"
41 SearchPolicy(False, False, PathSeparator.DOT, PathSeparator.DOT):
42 → "ProductService.similar.schema.json" (только класс+метод)
44 SearchPolicy(True, True, PathSeparator.SLASH, PathSeparator.DOT):
45 → "perekrestok_api/endpoints/catalog/ProductService.similar.schema.json"
47 SearchPolicy(False, True, PathSeparator.NONE, PathSeparator.NONE):
48 → "ProductServicesimilar.schema.json"
49 """
50 self.include_package_name = include_package_name
51 self.include_path_to_file = include_path_to_file
52 self.path_to_file_separator = path_to_file_separator
53 self.path_to_class_separator = path_to_class_separator
54 self.custom_patterns = custom_patterns or []
56 def __repr__(self) -> str:
57 return (
58 f"SearchPolicy(include_package_name={self.include_package_name}, "
59 f"include_path_to_file={self.include_path_to_file}, "
60 f"path_to_file_separator={self.path_to_file_separator}, "
61 f"path_to_class_separator={self.path_to_class_separator})"
62 )