Skip to content

refactor connection establishment #180

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

Merged
merged 1 commit into from
Dec 24, 2014
Merged

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Dec 18, 2014

reduces duplicated code, and makes it easier for future changes
to connection establishment because it's all in one place now


private

def use_connection(auth)
Copy link
Member

Choose a reason for hiding this comment

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

Needs documentation.

What are your thoughts on accepting the full args here instead of just the auth hash? While we're only using the auth portion, it seems overly specific for the scope of the method (connection management) and could evolve to need all of the connection options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documented, and switched to passing the full args hash

if @open_connection
yield @open_connection
else
@result = 0
Copy link
Member

Choose a reason for hiding this comment

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

We need to pull @result out of this method. It would be fine to have a local result that gets passed back to the caller.

0 is a strange default, too.

@ccutrer
Copy link
Contributor Author

ccutrer commented Dec 19, 2014

@mtodd - yeah, the @Result was weird, but it's what was there before. documentation already added in the latest version. I'll refactor it into returning it

reduces duplicated code, and makes it easier for future changes
to connection establishment because it's all in one place now
@ccutrer
Copy link
Contributor Author

ccutrer commented Dec 19, 2014

new version without assigning to @Result directly in use_connection is pushed

@mtodd
Copy link
Member

mtodd commented Dec 19, 2014

@ccutrer rebasing/force-pushing changes isn't necessary, though it's fine if that's your preference.

RE: using @result in use_connection (#180 (diff)) needs to be refactored to not change the state of an instance variable. We should be able to achieve our results with a local variable in use_connection and worry about managing the instance variable @result in the caller.

@mtodd
Copy link
Member

mtodd commented Dec 19, 2014

@ccutrer thanks for the super quick iteration on this PR, much happier with this version!

I'll hold off until @jch gets a chance to review but 👍 to merge this.

# Yields an open connection if there is one, otherwise establishes a new
# connection, binds, and yields it. If binding fails, it will return the
# result from that, and :use_connection: will not yield at all. If not
# the return value is whatever is returned from the block.
Copy link
Member

Choose a reason for hiding this comment

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

Was thinking it'd be good to document that the result of the block is passed through, since that's relevant to the @result = assignment we do in the caller. Not a blocker but would be good to communicate that.

Copy link
Member

Choose a reason for hiding this comment

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

Derp, didn't read well enough, that's exactly what's documented here.

end
ensure
conn.close if conn
end
Copy link
Member

Choose a reason for hiding this comment

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

This method feels very similar to Net::LDAP#open.

@mtodd
Copy link
Member

mtodd commented Dec 24, 2014

Think this is good to go. My comments aren't blockers, and this sets us up to iterate more ably than we were before so I think holding off would be pointless.

mtodd added a commit that referenced this pull request Dec 24, 2014
refactor connection establishment
@mtodd mtodd merged commit a89d094 into ruby-ldap:master Dec 24, 2014
@jch jch mentioned this pull request Jan 21, 2015
astratto pushed a commit to astratto/ruby-net-ldap that referenced this pull request Dec 18, 2015
@ccutrer ccutrer deleted the use_connection branch March 1, 2023 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants