Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions source/HOP-Extra/HOPZincHandlerAdaptor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : 'HOPCatchAllSegment',
#instVars : [
'routeMatch',
'handlerClass'
'handlerClass',
'handler'
],
#category : 'HOP-Extra',
#package : 'HOP-Extra'
Expand All @@ -26,12 +27,26 @@ HOPZincHandlerAdaptor >> atMethod: aString ifAbsent: aBlock [

{ #category : 'execution' }
HOPZincHandlerAdaptor >> execute [
^ handlerClass new handleRequest: routeMatch request
^ self handler handleRequest: routeMatch request
]

{ #category : 'accessing' }
HOPZincHandlerAdaptor >> handler [
"A handler given as an object is used as it is; given as a class, a fresh one per request."
^ handler ifNil: [ handlerClass new ]
]

{ #category : 'accessing' }
HOPZincHandlerAdaptor >> handler: anObject [
"Anything that answers handleRequest: with a ZnResponse. Naming the class instead leaves
nobody a moment to configure it - the object is born inside execute and used in the same
line, so a handler that has to be told something cannot be told anything."
handler := anObject
]

{ #category : 'public' }
HOPZincHandlerAdaptor >> handleRoute: aRouteMatch [
^ handlerClass new handleRequest: aRouteMatch request
^ self handler handleRequest: aRouteMatch request
]

{ #category : 'accessing' }
Expand Down
Loading