4

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?

MartinW
  • 4,966
  • 2
  • 24
  • 60
  • I really don't get your problem. Why would I load an arbitrary version in the first place? Just make a new Version with the correct default and everything will be fine when checking out the most recent one. – Leo Feb 12 '13 at 20:16
  • Someone might update her version as soon as there is a new one available. – MartinW Feb 12 '13 at 20:18

1 Answers1

3

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.

codefrau
  • 4,583
  • 17
  • 17
  • "Be careful though: If another package version has the same exact initialize class method, it will not be executed again." Ok, that is exactly what i experienced in the first place! I chose a simpler example to illustrate my question - and this example was obviously badly chosen.. – MartinW Feb 13 '13 at 12:31
  • So i updated my example to reflect my problem correctly. (means you could perhaps update the answer as well, because now, initialize will no longer be executed?) – MartinW Feb 13 '13 at 12:36
  • "So if you want to force execution of the initialize method, you at least need to give it a different timestamp." So this seems the solution. But it is also a bit strange ;) Tank you for your comprehensive explanations! – MartinW Feb 13 '13 at 12:39
  • In your changed example I guess you wanted to say "self defaultParameter". – codefrau Feb 13 '13 at 16:50