Skip to main content
Engineering LibreTexts

7.3: Using Gofer

  • Page ID
    43829
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Using Gofer is simple: you need to specify a location, the package to be loaded and finally the operation to be performed. The location often represents a file system been it an HTTP, a FTP or simply a hard-disc. The location is the same as the one used to access a Monticello repository. For example it is 'http://smalltalkhub.com/mc/MyAccount/MyPackage/main' as used in the following expression.

    MCHttpRepository
        location: 'http://smalltalkhub.com/mc/MyAccount/MyPackage/main'
        user: ''
        password: ''
    

    Here is a typical Gofer script: it says that we want to load the package PBE2GoferExample from the repository PBE2GoferExample that is available on http://www.smalltalkhub.com in the account of JannikLaval.

    Gofer new
        url: 'http://smalltalkhub.com/mc/PharoBooks/GoferExample/main';
        package: 'PBE2GoferExample';
        load 
    

    When the repository (HTTP or FTP) requires an identification, the message url:username:password: is available. Pay close attention as this is a single message, so do not put cascade in between. The message directory: supports the access to local files.

    Gofer new
        url: 'http://smalltalkhub.com/mc/PharoBooks/GoferExample/main'
        username: 'pharoUser'
        password: 'pharoPwd';
        package: 'PBE2GoferExample';
        load.
    
    "we work on the project PBE2GoferExample and provide credentials"
    Gofer new
        url: 'http://smalltalkhub.com/mc/PharoBooks/GoferExample/main/PBE2GoferExample'
        username: 'pharoUser'
        password: 'pharoPwd';
        package: 'PBE2GoferExample';        "define the package to be loaded"
        disablePackageCache;                "disable package lookup in local cache"
        disableRepositoryErrors;            "stop the error raising"
        load.                               "load the package"
    

    Since the same public servers are often used, Gofer’s API offers a number of shortcuts to shorten the scripts. Often, we want to write a script and give it to other people to load our code. In such a case having to specify a password is not really adequate. Here is an example for smalltalkHub (which has some verbose urls such as ’http://smalltalkhub.com/mc/PharoBooks/GoferExample/main’ for the project GoferExample). We use the smalltalkhubUser:project: message and just specify the minimal information. In this chapter, we also use squeaksource3: as a shortcut for http://ss3.gemtalksystems.com/ss.

    "Specifying a user but no password"
    Gofer new
        smalltalkhubUser: ’PharoBooks’ project: ’GoferExample’;
        package: 'PBE2GoferExample';
        load
    

    In addition, when Gofer does not succeed to load a package in a specified URL, it looks in the local cache which is normally at the root of your image. It is possible to force Gofer not to use the cache using the message disablePackageCache or to use it using the message enablePackageCache.

    In a similar manner, Gofer returns an error when one of the repositories is not reachable. We can instruct it to ignore such errors using the message disableRepositoryErrors. To enable it the message we can use the message enableRepositoryErrors.

    Package Identification

    Once an URL and the option are specified, we should define the packages we want to load. Using the message version: defines the exact version to load, while the message package: should be used to load the latest version available in all the repositories.

    The following example load the version 2 of the package.

    Gofer new
        smalltalkhubUser: 'PharoBooks' project: 'GoferExample';
        version: 'PBE2GoferExample-janniklaval.1';
        load
    

    We can also specify some constraints to identify packages using the message package: aString constraint: aBlock to pass a block.

    For example the following code will load the latest version of the package saved by the developer named janniklaval.

    Gofer new
        smalltalkhubUser: 'PharoBooks' project: 'GoferExample';
        package: 'PBE2GoferExample'
        constraint: [ :version | version author = 'janniklaval' ];
        load
    

    This page titled 7.3: Using Gofer is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.