Skip to content

Commit

Permalink
Merge pull request #144 from ba-st/minor_improvements
Browse files Browse the repository at this point in the history
Improve portability of ApplicationControlCommand
  • Loading branch information
gcotelli authored Dec 29, 2021
2 parents 74309d2 + 04c00aa commit 4312dad
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 13 deletions.
11 changes: 10 additions & 1 deletion source/Stargate-API-Skeleton/StargateApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ StargateApplication >> configureGlobalErrorHandlerIn: api [
yourself
];
on: Exit addErrorHandler: [ :exit |
exit isSuccess then: [ api stop ].
exit isSuccess then: [ self stop ].
exit pass
]
]
Expand Down Expand Up @@ -203,6 +203,14 @@ StargateApplication >> logAPIVersion [
LaunchpadLogRecord emitInfo: ( 'API Version: <1s>' expandMacrosWith: self class version )
]

{ #category : #'private - accessing' }
StargateApplication >> loggersConfiguration [

^ Dictionary new
at: #enabled put: true;
yourself
]

{ #category : #'private - accessing' }
StargateApplication >> metricsConfiguration [

Expand All @@ -226,6 +234,7 @@ StargateApplication >> operationsConfiguration [
at: ApplicationInfoPlugin endpoint put: self applicationInfoConfiguration;
at: ApplicationConfigurationPlugin endpoint put: self applicationConfigurationConfiguration;
at: ApplicationControlPlugin endpoint put: self applicationControlConfiguration;
at: LoggersPlugin endpoint put: self loggersConfiguration;
yourself
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,34 @@ ApplicationControlCommandTest >> testAccessing [

self
assert: command methodName equals: 'shutdown';
assert: command parameterCount equals: 0
assert: command parameterCount equals: 0;
assert: command parameterNames isEmpty
]

{ #category : #tests }
ApplicationControlCommandTest >> testCannotCreateUnnamed [

self should: [ ApplicationControlCommand named: '' executing: [ self fail ] ]
raise: InstanceCreationFailed
withMessageText: 'Cannot create an unnamed command'
]

{ #category : #tests }
ApplicationControlCommandTest >> testCannotCreateWhenArgumentCountIsMismatched [

self
should: [ ApplicationControlCommand named: 'echo' executing: [ :message | self fail ] ]
raise: InstanceCreationFailed
withMessageText: 'The number of parameter names doesn''t match the block arity';
should: [
ApplicationControlCommand named: 'echo' withArgumentNames: #( message ) executing: [ self fail ] ]
raise: InstanceCreationFailed
withMessageText: 'The number of parameter names doesn''t match the block arity';
should: [
ApplicationControlCommand named: 'echo'
withArgumentNames: #( message async )
executing: [ :message | self fail ]
]
raise: InstanceCreationFailed withMessageText:
'The number of parameter names doesn''t match the block arity'
]
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ ApplicationControlPluginAPITest >> requiredPermissions [
{ #category : #running }
ApplicationControlPluginAPITest >> setUp [

ApplicationControlPlugin
registerAsAvailableCommand: ( ApplicationControlCommand named: 'echo' executing: [ :message | message ] ).
ApplicationControlPlugin registerAsAvailableCommand: ( ApplicationControlCommand named: 'echo'
withArgumentNames: #( message )
executing: [ :message | message ] ).
super setUp
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,48 @@ Class {
#superclass : #Object,
#instVars : [
'methodName',
'actionBlock'
'actionBlock',
'parameterNames'
],
#category : #'Stargate-Application-Control'
}

{ #category : #'instance creation' }
ApplicationControlCommand class >> named: aMethodName executing: aBlockClosure [

AssertionChecker
enforce: [ aMethodName notEmpty ]
because: 'Cannot create an unnamed command'
raising: InstanceCreationFailed.
^ self named: aMethodName withArgumentNames: #( ) executing: aBlockClosure
]

{ #category : #'instance creation' }
ApplicationControlCommand class >> named: aMethodName withArgumentNames: argumentNames executing: aBlockClosure [

AssertionCheckerBuilder new
raising: InstanceCreationFailed;
checking: [ :asserter |
asserter
enforce: [ aMethodName notEmpty ] because: 'Cannot create an unnamed command';
enforce: [ argumentNames size = aBlockClosure argumentCount ]
because: 'The number of parameter names doesn''t match the block arity'
];
buildAndCheck.


^ self new initializeNamed: aMethodName executing: aBlockClosure
^ self new initializeNamed: aMethodName withArgumentNames: argumentNames executing: aBlockClosure
]

{ #category : #configuring }
ApplicationControlCommand >> addTo: aJsonRPCRequestHandler [

aJsonRPCRequestHandler addHandlerNamed: methodName evaluating: actionBlock
aJsonRPCRequestHandler addHandlerNamed: methodName
withArgumentNames: parameterNames
evaluating: actionBlock
]

{ #category : #initialization }
ApplicationControlCommand >> initializeNamed: aMethodName executing: aBlockClosure [
ApplicationControlCommand >> initializeNamed: aMethodName withArgumentNames: theArgumentNames executing: aBlockClosure [

methodName := aMethodName.
parameterNames := theArgumentNames.
actionBlock := aBlockClosure
]

Expand All @@ -45,5 +61,11 @@ ApplicationControlCommand >> methodName [
{ #category : #accessing }
ApplicationControlCommand >> parameterCount [

^ actionBlock argumentCount
^ parameterNames size
]

{ #category : #accessing }
ApplicationControlCommand >> parameterNames [

^ parameterNames
]

0 comments on commit 4312dad

Please sign in to comment.