Is there a specific method that would get executed in a class when i load a Monticello package containing this class?

StackOverflow https://stackoverflow.com/questions/14840613

Question

Is there a specific method that would get executed in a class when i load a Monticello package containing this class?

An 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 for the ImportantParameter,

SomeMonticelloPackage-MyName.2.mcz:

SomeClass class>>defaultParameter
    ^ true

SomeClass class>>initialize
    ImportantParameter := self defaultParameter
  • If i load Version 1 into an empty image, everything is ok.
  • If i load Version 2 into an empty image, everything is ok.
  • If i load first Version 1 and then Version 2, than Version 2 goes with the wrong default.

So i hope that some method exists that would be called in a class when a Monticello package containing this class is loaded into an image, so i could re-initialize the class. Is there one? Is there another solution to this problem?

Was it helpful?

Solution

Yes there is a specific method that gets executed when you load an MC package: The initialize method!

To be more precise, it gets executed if it the initialize method is different from the one that already is in the image. MC treats these class initializers specially (just like they are treated specially when you use change sets instead of Monticello).

So in your example, everything is fine. Loading the second version of initialize will cause it to be executed. (Edit: now that you updated your example so initialize is not itself modified, you need to follow the advice in my next paragraph).

Be careful though: If another package version has the same exact initialize class method, it will not be executed again. This is because Monticello, when loading a package, only considers the methods that are different from what's in your image, and what the loading version offers. So if you want to force execution of the initialize method, you at least need to give it a different timestamp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top