Skip to content

Commit

Permalink
Extend NullConfig to allow it to be used for simple testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
macta committed May 7, 2024
1 parent 3611d90 commit 2c3c1b5
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 165 deletions.
52 changes: 24 additions & 28 deletions source/Launchpad-Configuration/ApplicationConfiguration.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
Class {
#name : 'ApplicationConfiguration',
#superclass : 'Object',
#name : #ApplicationConfiguration,
#superclass : #Object,
#instVars : [
'parameters',
'provider',
'values'
],
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration',
#'gs_options' : [
'dbTransient'
]
#category : 'Launchpad-Configuration'
}

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ApplicationConfiguration class >> forAll: parameters providedBy: aConfigurationProvider [

^ self new initializeForAll: parameters providedBy: aConfigurationProvider
]

{ #category : 'converting' }
{ #category : #converting }
ApplicationConfiguration >> asCommandLineOn: stream [

( parameters sorted: #commandLineArgumentName ascending ) do: [ :parameter |
Expand All @@ -32,7 +28,7 @@ ApplicationConfiguration >> asCommandLineOn: stream [
]
]

{ #category : 'converting' }
{ #category : #converting }
ApplicationConfiguration >> asEnvironmentOn: stream [

( parameters sorted: #environmentVariableName ascending ) do: [ :parameter |
Expand All @@ -48,7 +44,7 @@ ApplicationConfiguration >> asEnvironmentOn: stream [
]
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> asIniFile: aParameterCollection on: stream [

( aParameterCollection sorted: #attributeName ascending ) do: [ :parameter |
Expand All @@ -66,7 +62,7 @@ ApplicationConfiguration >> asIniFile: aParameterCollection on: stream [
]
]

{ #category : 'converting' }
{ #category : #converting }
ApplicationConfiguration >> asIniFileOn: stream [

| settingsInSection |
Expand All @@ -86,13 +82,13 @@ ApplicationConfiguration >> asIniFileOn: stream [
]
]

{ #category : 'converting' }
{ #category : #converting }
ApplicationConfiguration >> asJson [

^ String streamContents: [ :stream | self asJsonOn: stream ]
]

{ #category : 'converting' }
{ #category : #converting }
ApplicationConfiguration >> asJsonOn: stream [

^ ( NeoJSONWriterSortingKeys on: stream )
Expand All @@ -101,7 +97,7 @@ ApplicationConfiguration >> asJsonOn: stream [
nextPut: values
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> assert: section isNotInConflictWithParameterNamed: name [

"Sections in the configuration are instances of NeoJSONObject, if we get
Expand All @@ -112,7 +108,7 @@ ApplicationConfiguration >> assert: section isNotInConflictWithParameterNamed: n
raising: ConflictingObjectFound
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> containingSectionFor: parameter startingAt: resolvedValues [

| currentSection |
Expand All @@ -126,21 +122,21 @@ ApplicationConfiguration >> containingSectionFor: parameter startingAt: resolved
^ currentSection
]

{ #category : 'reflective operations' }
{ #category : #'reflective operations' }
ApplicationConfiguration >> doesNotUnderstand: message [

^ self valueAt: message selector ifAbsent: [ super doesNotUnderstand: message ]
]

{ #category : 'initialization' }
{ #category : #initialization }
ApplicationConfiguration >> initializeForAll: aParameterCollection providedBy: aConfigurationProvider [

parameters := aParameterCollection.
provider := aConfigurationProvider.
self resolveParameterValues
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> missingConfigurationFor: parameter [

LogRecord emitError:
Expand All @@ -149,20 +145,20 @@ ApplicationConfiguration >> missingConfigurationFor: parameter [
( '"<1s>" parameter not present.' expandMacrosWith: parameter name )
]

{ #category : 'accessing' }
{ #category : #accessing }
ApplicationConfiguration >> parameters [

^ parameters
]

{ #category : 'actions' }
{ #category : #actions }
ApplicationConfiguration >> reload [

provider reloadConfiguration.
self resolveParameterValues
]

{ #category : 'initialization' }
{ #category : #initialization }
ApplicationConfiguration >> resolveParameterValues [

| section resolvedValues |
Expand All @@ -181,39 +177,39 @@ ApplicationConfiguration >> resolveParameterValues [
self synchronizeValuesWith: resolvedValues
]

{ #category : 'reflective operations' }
{ #category : #'reflective operations' }
ApplicationConfiguration >> respondsTo: selector [

^ ( super respondsTo: selector ) or: [ values includesKey: selector ]
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> signalAsConflictingParameter: parameter [

ConflictingObjectFound signal: ( 'Conflicting parameter: "<1s>"' expandMacrosWith: parameter name )
]

{ #category : 'private' }
{ #category : #private }
ApplicationConfiguration >> synchronizeValuesWith: resolvedValues [

values := resolvedValues
]

{ #category : 'accessing' }
{ #category : #accessing }
ApplicationConfiguration >> valueAt: aKey [

^ self valueAt: aKey ifAbsent: [ KeyNotFound signalFor: aKey ]
]

{ #category : 'accessing' }
{ #category : #accessing }
ApplicationConfiguration >> valueAt: aKey ifAbsent: aBlock [
"For configuration access without DNU handling, provide standard Dictionary api.
With normal configuration parameters, there should never be an absent value, but provide the standard ifAbsent option for correctness"

^ values at: aKey ifAbsent: aBlock
]

{ #category : 'accessing' }
{ #category : #accessing }
ApplicationConfiguration >> valueFor: aParameter [

| section |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
Class {
#name : 'ConfigurationFromCommandLineProvider',
#superclass : 'ConfigurationProvider',
#name : #ConfigurationFromCommandLineProvider,
#superclass : #ConfigurationProvider,
#instVars : [
'commandLine',
'nextProvider'
],
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
#category : 'Launchpad-Configuration'
}

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ConfigurationFromCommandLineProvider class >> over: aCommandLine [

^ self over: aCommandLine chainedWith: NullConfigurationProvider new
]

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ConfigurationFromCommandLineProvider class >> over: aCommandLine chainedWith: aConfigurationProvider [

^ self new initializeOver: aCommandLine chainedWith: aConfigurationProvider
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromCommandLineProvider >> initializeOver: aCommandLine chainedWith: aConfigurationProvider [

commandLine := aCommandLine.
nextProvider := aConfigurationProvider
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromCommandLineProvider >> reloadConfiguration [

nextProvider reloadConfiguration
]

{ #category : 'resolving' }
{ #category : #resolving }
ConfigurationFromCommandLineProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ commandLine optionAt: aConfigurationParameter commandLineArgumentName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
Class {
#name : 'ConfigurationFromEnvironmentProvider',
#superclass : 'ConfigurationProvider',
#name : #ConfigurationFromEnvironmentProvider,
#superclass : #ConfigurationProvider,
#instVars : [
'nextProvider'
],
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
#category : 'Launchpad-Configuration'
}

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ConfigurationFromEnvironmentProvider class >> chainedWith: aConfigurationProvider [

^ super new initializeChainedWith: aConfigurationProvider
]

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ConfigurationFromEnvironmentProvider class >> new [

^ self chainedWith: NullConfigurationProvider new
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromEnvironmentProvider >> initializeChainedWith: aConfigurationProvider [

nextProvider := aConfigurationProvider
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromEnvironmentProvider >> reloadConfiguration [

^ nextProvider reloadConfiguration
]

{ #category : 'resolving' }
{ #category : #resolving }
ConfigurationFromEnvironmentProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ LanguagePlatform current os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
Class {
#name : 'ConfigurationFromIniSettingsFileProvider',
#superclass : 'ConfigurationFromSettingsFileProvider',
#name : #ConfigurationFromIniSettingsFileProvider,
#superclass : #ConfigurationFromSettingsFileProvider,
#instVars : [
'fileReference',
'iniData',
'nextProvider'
],
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
#category : 'Launchpad-Configuration'
}

{ #category : 'testing' }
{ #category : #testing }
ConfigurationFromIniSettingsFileProvider class >> canHandle: aFileReference [

^ aFileReference extension = 'ini'
]

{ #category : 'instance creation' }
{ #category : #'instance creation' }
ConfigurationFromIniSettingsFileProvider class >> loading: anIniFileReference chainedWith: aConfigurationProvider [

^ self new initializeLoading: anIniFileReference chainedWith: aConfigurationProvider
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromIniSettingsFileProvider >> initializeLoading: aFileReference chainedWith: aConfigurationProvider [

fileReference := aFileReference.
self loadConfiguration.
nextProvider := aConfigurationProvider
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromIniSettingsFileProvider >> loadConfiguration [

fileReference readStreamDo: [ :stream | iniData := ( IniReader on: stream ) parse ]
]

{ #category : 'initialization' }
{ #category : #initialization }
ConfigurationFromIniSettingsFileProvider >> reloadConfiguration [

self loadConfiguration.
nextProvider reloadConfiguration
]

{ #category : 'resolving' }
{ #category : #resolving }
ConfigurationFromIniSettingsFileProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ iniData
Expand Down
Loading

0 comments on commit 2c3c1b5

Please sign in to comment.