-
Notifications
You must be signed in to change notification settings - Fork 116
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
Allow using specific consitency on all methods #165
Changes from 1 commit
5b66143
7a0097b
d77cc72
91ab964
8241bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ class Datacenter < Diplomat::RestClient | |
# Get an array of all avaliable datacenters accessible by the local consul agent | ||
# @param meta [Hash] output structure containing header information about the request (index) | ||
# @return [OpenStruct] all datacenters avaliable to this consul agent | ||
def get(meta = nil) | ||
def get(meta = nil, options = nil) | ||
url = ['/v1/catalog/datacenters'] | ||
url << use_consistency(options) if use_consistency(options, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use 'if use_consistency' everywhere while it could be integrated into use_consistency (or a wrapper of both...) it's not very conservative if you forget one use_consistency call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did it in next patch |
||
|
||
ret = @conn.get concat_url url | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,19 @@ def use_named_parameter(name, value) | |
value ? ["#{name}=#{value}"] : [] | ||
end | ||
|
||
def use_consistency(options, default_value = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get the point of having a default value if it's always set to nil, and checked if its value is not nil... Better just remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was to avoid modifying lib/diplomat/kv.rb, but I did the other way around finally in next patch |
||
return default_value unless options | ||
case options[:consistency] | ||
when 'consistent' | ||
return use_named_parameter('consistent', 'consistent') | ||
when 'stale' | ||
return use_named_parameter('stale', 'stale') | ||
when 'leader' | ||
return use_named_parameter('leader', 'leader') | ||
end | ||
default_value | ||
end | ||
|
||
# Assemble a url from an array of parts. | ||
# @param parts [Array] the url chunks to be assembled | ||
# @return [String] the resultant url string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment / Doc shall be updated to take into account the new param