bolshakov / stoplight

:traffic_light: Traffic control for code.
http://bolshakov.github.io/stoplight/
MIT License
384 stars 40 forks source link

feat | Light lock interface improvement #170

Closed Lokideos closed 1 year ago

Lokideos commented 1 year ago

This ticket aims to improve the interface of the locking light state as described in https://github.com/bolshakov/stoplight/issues/162.

Previously, if we needed to lock the light state, we used the data store interface instead of the light interface. This approach exposed the implementation of light locking and potentially allowed the locking state of one light via the interface of another light. Now we call #lock directly on the light and also hide the implementation of light locking.

# was
light.data_store.set_state(light, Stoplight::State::LOCKED_RED)
# now
light.lock(Stoplight::Color::RED)

We also introduce the #unlock method, which hides the implementation of unlocking the light and simplifies light unlocking:

# was
light.data_store.set_state(light, Stoplight::State::UNLOCKED)
# now
light.unlock