Skip to content

Commit

Permalink
Implement Disable() on handler configurers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Jul 16, 2024
1 parent 53caa25 commit 9123284
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 19 deletions.
9 changes: 6 additions & 3 deletions aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type RichAggregate interface {
// configuration related panic values to errors.
func FromAggregate(h dogma.AggregateMessageHandler) RichAggregate {
cfg := &aggregate{
entity: entity{
rt: reflect.TypeOf(h),
handler: handler{
entity: entity{
rt: reflect.TypeOf(h),
},
},
impl: h,
}
Expand All @@ -40,6 +42,7 @@ func FromAggregate(h dogma.AggregateMessageHandler) RichAggregate {
entityConfigurer: entityConfigurer{
entity: &cfg.entity,
},
handler: &cfg.handler,
},
}

Expand All @@ -54,7 +57,7 @@ func FromAggregate(h dogma.AggregateMessageHandler) RichAggregate {

// aggregate is an implementation of RichAggregate.
type aggregate struct {
entity
handler

impl dogma.AggregateMessageHandler
}
Expand Down
24 changes: 23 additions & 1 deletion aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("func FromAggregate()", func() {
When("the configuration is valid", func() {
var cfg RichAggregate

BeforeEach(func() {
JustBeforeEach(func() {
cfg = FromAggregate(handler)
})

Expand Down Expand Up @@ -124,11 +124,33 @@ var _ = Describe("func FromAggregate()", func() {
})
})

Describe("func IsDisabled()", func() {
It("returns false", func() {
Expect(cfg.IsDisabled()).To(BeFalse())
})
})

Describe("func Handler()", func() {
It("returns the underlying handler", func() {
Expect(cfg.Handler()).To(BeIdenticalTo(handler))
})
})

When("the handler is disabled", func() {
BeforeEach(func() {
configure := handler.ConfigureFunc
handler.ConfigureFunc = func(c dogma.AggregateConfigurer) {
configure(c)
c.Disable()
}
})

Describe("func IsDisabled()", func() {
It("returns true", func() {
Expect(cfg.IsDisabled()).To(BeTrue())
})
})
})
})

DescribeTable(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dogmatiq/configkit
go 1.21

require (
github.com/dogmatiq/dogma v0.13.0
github.com/dogmatiq/dogma v0.13.1-0.20240708211023-af9214272677
github.com/dogmatiq/iago v0.4.0
github.com/dogmatiq/interopspec v0.5.3
github.com/emicklei/dot v1.6.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dogmatiq/dogma v0.13.0 h1:MKk9MHErGKD53Y+43I4fcoPZMQjX0N2DUZEc4rLp+Hk=
github.com/dogmatiq/dogma v0.13.0/go.mod h1:9lyVA+6V2+E/exV0IrBOrkUiyFwIATEhv+b0vnB2umQ=
github.com/dogmatiq/dogma v0.13.1-0.20240708211023-af9214272677 h1:2DDD3+89VQre3EOvkJL1syN5EUXNU06uAkXE5/fsaBU=
github.com/dogmatiq/dogma v0.13.1-0.20240708211023-af9214272677/go.mod h1:9lyVA+6V2+E/exV0IrBOrkUiyFwIATEhv+b0vnB2umQ=
github.com/dogmatiq/iago v0.4.0 h1:57nZqVT34IZxtCZEW/RFif7DNUEjMXgevfr/Mmd0N8I=
github.com/dogmatiq/iago v0.4.0/go.mod h1:fishMWBtzYcjgis6d873VTv9kFm/wHYLOzOyO9ECBDc=
github.com/dogmatiq/interopspec v0.5.3 h1:AES184nLWcek8/vafykZJLmm59NlRiYiC40Tll8hEeg=
Expand Down
15 changes: 15 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ type Handler interface {

// HandlerType returns the type of handler.
HandlerType() HandlerType

// IsDisabled returns true if the handler is disabled.
IsDisabled() bool
}

// RichHandler is a specialization of the Handler interface that exposes
Expand All @@ -15,6 +18,9 @@ type RichHandler interface {

// HandlerType returns the type of handler.
HandlerType() HandlerType

// IsDisabled returns true if the handler is disabled.
IsDisabled() bool
}

// IsHandlerEqual compares two handlers for equality.
Expand All @@ -38,3 +44,12 @@ func IsHandlerEqual(a, b Handler) bool {
a.HandlerType() == b.HandlerType() &&
a.MessageNames().IsEqual(b.MessageNames())
}

type handler struct {
entity
isDisabled bool
}

func (h *handler) IsDisabled() bool {
return h.isDisabled
}
5 changes: 5 additions & 0 deletions handlerconfigurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// - [dogma.ProjectionConfigurer]
type handlerConfigurer struct {
entityConfigurer
handler *handler
}

func (c *handlerConfigurer) route(r dogma.Route) {
Expand Down Expand Up @@ -155,3 +156,7 @@ func (c *handlerConfigurer) mustProduce(r message.Role) {
route,
)
}

func (c *handlerConfigurer) Disable(...dogma.DisableOption) {
c.handler.isDisabled = true
}
9 changes: 6 additions & 3 deletions integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type RichIntegration interface {
// configuration related panic values to errors.
func FromIntegration(h dogma.IntegrationMessageHandler) RichIntegration {
cfg := &integration{
entity: entity{
rt: reflect.TypeOf(h),
handler: handler{
entity: entity{
rt: reflect.TypeOf(h),
},
},
impl: h,
}
Expand All @@ -40,6 +42,7 @@ func FromIntegration(h dogma.IntegrationMessageHandler) RichIntegration {
entityConfigurer: entityConfigurer{
entity: &cfg.entity,
},
handler: &cfg.handler,
},
}

Expand All @@ -53,7 +56,7 @@ func FromIntegration(h dogma.IntegrationMessageHandler) RichIntegration {

// integration is an implementation of RichIntegration.
type integration struct {
entity
handler

impl dogma.IntegrationMessageHandler
}
Expand Down
18 changes: 17 additions & 1 deletion integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("func FromIntegration()", func() {
When("the configuration is valid", func() {
var cfg RichIntegration

BeforeEach(func() {
JustBeforeEach(func() {
cfg = FromIntegration(handler)
})

Expand Down Expand Up @@ -130,6 +130,22 @@ var _ = Describe("func FromIntegration()", func() {
})
})

When("the handler is disabled", func() {
BeforeEach(func() {
configure := handler.ConfigureFunc
handler.ConfigureFunc = func(c dogma.IntegrationConfigurer) {
configure(c)
c.Disable()
}
})

Describe("func IsDisabled()", func() {
It("returns true", func() {
Expect(cfg.IsDisabled()).To(BeTrue())
})
})
})

When("the handler does not configure any event routes", func() {
BeforeEach(func() {
handler.ConfigureFunc = func(c dogma.IntegrationConfigurer) {
Expand Down
6 changes: 6 additions & 0 deletions internal/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Handler struct {
TypeNameValue string
MessageNamesValue configkit.EntityMessageNames
HandlerTypeValue configkit.HandlerType
IsDisabledValue bool
}

// Identity returns the identity of the entity.
Expand All @@ -67,6 +68,11 @@ func (h *Handler) HandlerType() configkit.HandlerType {
return h.HandlerTypeValue
}

// IsDisabled returns true if the handler is disabled.
func (h *Handler) IsDisabled() bool {
return h.IsDisabledValue
}

// AcceptVisitor calls the appropriate method on v for this entity type.
func (h *Handler) AcceptVisitor(ctx context.Context, v configkit.Visitor) error {
h.HandlerTypeValue.MustValidate()
Expand Down
9 changes: 6 additions & 3 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type RichProcess interface {
// configuration related panic values to errors.
func FromProcess(h dogma.ProcessMessageHandler) RichProcess {
cfg := &process{
entity: entity{
rt: reflect.TypeOf(h),
handler: handler{
entity: entity{
rt: reflect.TypeOf(h),
},
},
impl: h,
}
Expand All @@ -40,6 +42,7 @@ func FromProcess(h dogma.ProcessMessageHandler) RichProcess {
entityConfigurer: entityConfigurer{
entity: &cfg.entity,
},
handler: &cfg.handler,
},
}

Expand All @@ -54,7 +57,7 @@ func FromProcess(h dogma.ProcessMessageHandler) RichProcess {

// process is an implementation of RichProcess.
type process struct {
entity
handler

impl dogma.ProcessMessageHandler
}
Expand Down
18 changes: 17 additions & 1 deletion process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("func FromProcess()", func() {
When("the configuration is valid", func() {
var cfg RichProcess

BeforeEach(func() {
JustBeforeEach(func() {
cfg = FromProcess(handler)
})

Expand Down Expand Up @@ -134,6 +134,22 @@ var _ = Describe("func FromProcess()", func() {
Expect(cfg.Handler()).To(BeIdenticalTo(handler))
})
})

When("the handler is disabled", func() {
BeforeEach(func() {
configure := handler.ConfigureFunc
handler.ConfigureFunc = func(c dogma.ProcessConfigurer) {
configure(c)
c.Disable()
}
})

Describe("func IsDisabled()", func() {
It("returns true", func() {
Expect(cfg.IsDisabled()).To(BeTrue())
})
})
})
})

DescribeTable(
Expand Down
9 changes: 6 additions & 3 deletions projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ type RichProjection interface {
// configuration related panic values to errors.
func FromProjection(h dogma.ProjectionMessageHandler) RichProjection {
cfg := &projection{
entity: entity{
rt: reflect.TypeOf(h),
handler: handler{
entity: entity{
rt: reflect.TypeOf(h),
},
},
impl: h,
deliveryPolicy: dogma.UnicastProjectionDeliveryPolicy{},
Expand All @@ -44,6 +46,7 @@ func FromProjection(h dogma.ProjectionMessageHandler) RichProjection {
entityConfigurer: entityConfigurer{
entity: &cfg.entity,
},
handler: &cfg.handler,
},
}

Expand All @@ -61,7 +64,7 @@ func FromProjection(h dogma.ProjectionMessageHandler) RichProjection {

// projection is an implementation of RichProjection.
type projection struct {
entity
handler

impl dogma.ProjectionMessageHandler
deliveryPolicy dogma.ProjectionDeliveryPolicy
Expand Down
18 changes: 17 additions & 1 deletion projection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("func FromProjection()", func() {
When("the configuration is valid", func() {
var cfg RichProjection

BeforeEach(func() {
JustBeforeEach(func() {
cfg = FromProjection(handler)
})

Expand Down Expand Up @@ -137,6 +137,22 @@ var _ = Describe("func FromProjection()", func() {
Expect(cfg.Handler()).To(BeIdenticalTo(handler))
})
})

When("the handler is disabled", func() {
BeforeEach(func() {
configure := handler.ConfigureFunc
handler.ConfigureFunc = func(c dogma.ProjectionConfigurer) {
configure(c)
c.Disable()
}
})

Describe("func IsDisabled()", func() {
It("returns true", func() {
Expect(cfg.IsDisabled()).To(BeTrue())
})
})
})
})

DescribeTable(
Expand Down

0 comments on commit 9123284

Please sign in to comment.