Is there a special method that will be executed in the class when loading the Monticello package containing this class?

Is there a special method that will be executed in the class when loading the Monticello package containing this class?

Example:

Version 1,

SomeMonticelloPackage-MyName.1.mcz:

Object subclass: #SomeClass classVariableNames: 'ImportantParameter' SomeClass class>>defaultParameter ^ false SomeClass class>>initialize ImportantParameter := self defaultParameter 

In version 2, I change the default value for an important parameter,

SomeMonticelloPackage-MyName.2.mcz:

 SomeClass class>>defaultParameter ^ true SomeClass class>>initialize ImportantParameter := self defaultParameter 
  • If I upload version 1 to a blank image, everything is fine.
  • If I upload version 2 to a blank image, everything is fine.
  • If I download the first version 1 and then version 2, then version 2 comes with the wrong default value.

Therefore, I hope that there is some method that will be called in the class when the Monticello package containing this class is loaded into the image, so I could reinitialize the class. Is there any? Is there any other solution to this problem?

+4
source share
1 answer

Yes, there is a special method that starts when the MC package is downloaded: the initialize method!

To be more precise, it starts if the initialize method is different from the method that is already in the image. MC treats these class initializers on purpose (just like they treat on purpose when you use shifts instead of Monticello).

So in your example, everything is fine. Downloading the second version of initialize will execute it. (Edit: now that you have updated your example, so the initialization does not change on its own, you need to follow the recommendations in the next paragraph).

Be careful: if another version of the package has the same initialize class method, it will not be executed again. This is because Monticello, when downloading a package, takes into account only those methods that are different from what is in your image and what the download version offers. Therefore, if you want to enforce the initialize method, at least you need to give it a different timestamp.

+3
source

All Articles