MCServerRegistry.st
changeset 1056 930e6151a60d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCServerRegistry.st	Sun Aug 26 14:43:01 2018 +0200
@@ -0,0 +1,80 @@
+"{ Package: 'stx:goodies/monticello' }"
+
+"{ NameSpace: Smalltalk }"
+
+Object subclass:#MCServerRegistry
+	instanceVariableNames:'registry'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'SCM-Monticello-RemoteRepositories'
+!
+
+MCServerRegistry class instanceVariableNames:'uniqueInstance'
+
+"
+ No other class instance variables are inherited by this class.
+"
+!
+
+MCServerRegistry comment:'Registry for metacello servers'
+!
+
+
+!MCServerRegistry class methodsFor:'instance creation'!
+
+uniqueInstance
+
+	^ uniqueInstance ifNil: [ uniqueInstance := self new ].
+! !
+
+!MCServerRegistry methodsFor:'*Tests-Monticello'!
+
+removeCredentialsFor: aString 
+
+	registry removeKey: aString.
+! !
+
+!MCServerRegistry methodsFor:'initialization'!
+
+initialize
+
+	super initialize.
+	registry := Dictionary new.
+! !
+
+!MCServerRegistry methodsFor:'private'!
+
+repositoryAt: urlString credentialsDo: aBlock
+
+
+	| possibleMatches bestMatch |
+	possibleMatches := registry associations select: [ :e | urlString beginsWith: e key ].
+	possibleMatches isEmpty ifTrue: [ ^ aBlock value: '' value: '' ].
+	bestMatch := possibleMatches inject: possibleMatches anyOne into: [ :last :new | 
+		((new key asUrl path size > last key asUrl path size) 
+		"this is ugly, but URL always returns a path element, even an empty one..."
+		or: [ last key asUrl path size = 1 and: [ last key asUrl path last isEmpty ]]) 
+			ifTrue: [ new ]
+			ifFalse: [ last ]].
+	^ aBlock value: bestMatch value username value: bestMatch value password.
+! !
+
+!MCServerRegistry methodsFor:'public'!
+
+on: repositoryUrl beUser: nameString withPassword: passwordString
+
+	| credentials |
+	credentials := MCServerCredentials user: nameString password: passwordString.
+	registry at: repositoryUrl put: credentials.
+! !
+
+!MCServerRegistry class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+