Skip to content

Commit

Permalink
deal with ruby < 2.3 lacking Hash#dig
Browse files Browse the repository at this point in the history
  • Loading branch information
CamJN committed May 6, 2022
1 parent 9860e4c commit 3b6a2c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def query_pool_json
try_performing_ro_admin_basic_auth(request, @instance)
response = @instance.http_request("agents.s/core_api", request)
if response.code.to_i / 100 == 2
JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value.dig(:app_root,0,:value)}}
if RUBY_VERSION >= '2.3'
JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value.dig(:app_root,0,:value)}}
else
JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value[:app_root][0][:value]}}
end
elsif response.code.to_i == 401
if response["pool-empty"] == "true"
[]
Expand Down
6 changes: 5 additions & 1 deletion test/integration_tests/apache2_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ def get_newest_instance
request.basic_auth("ro_admin", instance.read_only_admin_password)
response = instance.http_request("agents.s/core_api", request)
if response.code.to_i / 100 == 2
groups = JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value.dig(:app_root,0,:value)}}
if RUBY_VERSION >= '2.3'
groups = JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value.dig(:app_root,0,:value)}}
else
groups = JSON.parse(response.body, symbolize_names: true).to_a.map{|(key,value)| {name: key.to_s, app_root: value[:app_root][0][:value]}}
end
else
raise response.body
end
Expand Down

0 comments on commit 3b6a2c3

Please sign in to comment.