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

feat | Light lock interface improvement #170

Merged

Conversation

Lokideos
Copy link
Collaborator

This ticket aims to improve the interface of the locking light state as described in #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

@Lokideos Lokideos self-assigned this Dec 10, 2022
@Lokideos Lokideos marked this pull request as ready for review December 10, 2022 08:53
bolshakov
bolshakov previously approved these changes Dec 10, 2022
Copy link
Owner

@bolshakov bolshakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @Lokideos 👏

I left a suggestion that I believe could simplify the code

@@ -26,6 +27,20 @@ def run
end
end

def lock(color)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one final thought. Would you mind adding yard docs to the method? Since it's a public integrate, let's document what it returns, I suggest returning either self of color. I lean toward a color, but don't have a strong opinion about that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to return Light.


def unlock
safely { data_store.set_state(self, Stoplight::State::UNLOCKED) }
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, we cannot return a color in this method 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about what to return then :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolshakov, because we can't return color in this method think that we should return Light here.

@Lokideos Lokideos force-pushed the feat-light-lock-interface-improvement branch from 8611475 to 8204f2e Compare December 17, 2022 11:50
@bolshakov bolshakov merged commit c97a3e2 into bolshakov:master Dec 19, 2022
@bolshakov bolshakov mentioned this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants