Reputation: 6981
I want to execute some code at image start-up time only if a package is loaded. I see that there exists
Smalltalk>>#addToStartUpList:
a method, which allows me to register a class which would provide startUp and shutDown hooks.
This is cool, but I don't want to execute this code manually. What's the recommended approach in Pharo?
Upvotes: 3
Views: 335
Reputation: 4357
You need to put the code somewhere. The usual way to add this kind of registering is in the #initialize method of a class in your package.
For example, something like this:
MyClassWithStartUp class>>#initialize
Smalltalk addToStartUpList: self
If your class MyClassWithStartUp is in the package you want to control... then it will be automatically registered when loaded.
Upvotes: 3
Reputation: 13386
Here http://pharobyexample.org/drafts/Metacello.pdf in section 1.10 you can se how pre and post load scripts can be specified. You can use them to setup startup list.
The approach that I use is to check for the package if a script itself (and I put script in ~/Library/Preferences/pharo/
.
For example consider this:
MCWorkingCopy allManagers
select: [ :e | e package name beginsWith: 'Renraku' ]
thenDo: [ :e |
| repository |
...
If you want to do the same for a bunch of repositories, or you can use #detect
for one and so on.
Upvotes: 2