[Lepiter]: Page Type Updating Should Be Repeatable, Handle All Subclasses
Situation: I have two custom page types which inherit from one another. Problems:
- the subclass is currently not recognized by GT
- when developing new page types, it is currently not easy to make existing DBs aware of them.
Currently:
LeDatabase>>#initialize
"..."
LePageType subclassesDo: [ :pageType |
pagesByType
at: pageType pageTypeClass
ifAbsentPut: [ Dictionary new ] ].
"..."
Solutions:
- should be:
LePageType allSubclassesDo: - Excerpted code should be extracted into its own method to be sent at other-than-intialization-time e.g.:
LeDatabase>>#updatePageTypes
LePageType allSubclassesDo: [ :pageType |
pagesByType
at: pageType pageTypeClass
ifAbsentPut: [ Dictionary new ] ].
The behavior of LeDatabase>>#initialize currently calls allSubclassesDo:. Furthermore, my PR introduces this in LePageType class>>#initialize. In your custom page type you just need to have a class side initialize and that logic will be called on the super call.
As with other class initialization code, independent of Lepiter, you do have to call it manually when originally developing locally. Once it's in source control and loaded with Metacello this code gets run automatcially, no way around the original manual part though.
The update of page types uses now allSubclassesDo:
Thanks! I see my updatePageTypes made it in as populatePageTypes, so I can update my initialization code. I also really like @botwhytho moving it into page type initialization - that should be the final piece to make this straightforward.