@@ -104,17 +104,7 @@ def _create_instance(self, path: str, /, **kwargs: Any) -> T:
104104 """Create an instance of 'T'."""
105105 raise NotImplementedError ()
106106
107- def reload (self ) -> Self :
108- """Reloads the collection from Connect.
109-
110- Returns
111- -------
112- Self
113- """
114- self ._cache = None
115- return self
116-
117- def _fetch (self ) -> List [T ]:
107+ def fetch (self ) -> List [T ]:
118108 """Fetch the collection.
119109
120110 Fetches the collection directly from Connect. This operation does not effect the cache state.
@@ -128,6 +118,16 @@ def _fetch(self) -> List[T]:
128118 results = response .json ()
129119 return [self ._to_instance (result ) for result in results ]
130120
121+ def reload (self ) -> Self :
122+ """Reloads the collection from Connect.
123+
124+ Returns
125+ -------
126+ Self
127+ """
128+ self ._cache = None
129+ return self
130+
131131 def _to_instance (self , result : dict ) -> T :
132132 """Converts a result into an instance of T."""
133133 uid = result [self ._uid ]
@@ -150,7 +150,7 @@ def _data(self) -> List[T]:
150150 reload
151151 """
152152 if self ._cache is None :
153- self ._cache = self ._fetch ()
153+ self ._cache = self .fetch ()
154154 return self ._cache
155155
156156 @overload
@@ -162,6 +162,9 @@ def __getitem__(self, index: slice) -> Sequence[T]: ...
162162 def __getitem__ (self , index ):
163163 return self ._data [index ]
164164
165+ def __iter__ (self ):
166+ return iter (self ._data )
167+
165168 def __len__ (self ) -> int :
166169 return len (self ._data )
167170
@@ -213,4 +216,5 @@ def find_by(self, **conditions: Any) -> Optional[T]:
213216 Optional[T]
214217 The first record matching the conditions, or `None` if no match is found.
215218 """
216- return next ((v for v in self ._data if v .items () >= conditions .items ()), None )
219+ collection = self .fetch ()
220+ return next ((v for v in collection if v .items () >= conditions .items ()), None )
0 commit comments