Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Symbolize kyes in config before accessing it
Browse files Browse the repository at this point in the history
  • Loading branch information
yudai committed Aug 27, 2013
1 parent b6e1743 commit 2d45d93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/cf/registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Registrar
def initialize(config)
@logger = Steno.logger("cf.registrar")

config = symbolize_keys(config)

@message_bus_uri = config[:mbus]
@host = config[:host]
@port = config[:port]
Expand Down Expand Up @@ -120,5 +122,14 @@ def setup_interval(interval)
send_registration_message
end
end

def symbolize_keys(hash)
return hash unless hash.is_a? Hash
Hash[
hash.each_pair.map do |k, v|
[k.to_sym, symbolize_keys(v)]
end
]
end
end
end
7 changes: 7 additions & 0 deletions spec/unit/registrar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ module Cf
its(:uuid) { should_not be_nil }
end
end

context "when there are values with String keys" do
let(:config) { { "host" => "h", :varz => { "username" => "user" } } }

its(:host) { should eq "h" }
its(:username) { should eq "user" }
end
end

describe "#register_with_router" do
Expand Down

0 comments on commit 2d45d93

Please sign in to comment.