Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock light state using the Light class interface #162

Closed
Lokideos opened this issue Dec 3, 2022 · 3 comments
Closed

Lock light state using the Light class interface #162

Lokideos opened this issue Dec 3, 2022 · 3 comments
Assignees
Milestone

Comments

@Lokideos
Copy link
Collaborator

Lokideos commented Dec 3, 2022

To manually lock the state of light, we use the data_store interface. For example:

light = Stoplight('example-locked') { true }
# => #<Stoplight::Light:..>
light.run
# => true
light.data_store.set_state(light, Stoplight::State::LOCKED_RED)
# => "locked_red"
light.run
# Stoplight::Error::RedLight: example-locked

However, it allows us to use the interface of one light to lock the state of any other light. To avoid this situation, I'd like to add the Light#set_state method, which will be called like this:

light = Stoplight('example-locked') { true }
light.set_state(Stoplight::State::LOCKED_RED)

This implementation will clearly show for what light we lock the state.

@bolshakov
Copy link
Owner

Maybe instead of emphasizing setting state, we can emphasize locking the circuit breaker:

light = Stoplight('example-locked') { true }
light.lock(Stoplight::Color::RED) 

Users don't have to know about the Stoplight::State::LOCKED_RED which is internal details aimed to distinguish red statute from locked red. What do you think?

@Lokideos
Copy link
Collaborator Author

Lokideos commented Dec 3, 2022

@bolshakov yes, that's a great idea! I also think that to unlock it, we can just use the Light#unlock method without any arguments. WDYT?

@bolshakov bolshakov added this to the v4.0.0 milestone Dec 3, 2022
@bolshakov
Copy link
Owner

This makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants