Skip to content

Commit d649ee0

Browse files
committed
Fix mutation of hash.
There was no reason to be mutating the hash. This is what was actually causing the `RuntimeError: can't modify frozen Hash` problem. What we simply wanted was to freeze the auth hash and the inner team array. To protected against future shallow values we just freeze all the inner values. Freezing an already frozen object is a no-op and thread safe; it will not raise an error. With this new logic we don't have to worry about threading. Though two or more threads may re-freeze the same object, it will not cause a crash. We chose to use `each` here, instead of `values.each`, so that we don't have to create the intermediate value array.
1 parent fbc60a6 commit d649ee0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/kracken/controllers/token_authenticatable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def cache_valid_auth(token, &generate_cache)
5151
def shallow_freeze(val)
5252
# `nil` is frozen in Ruby 2.2 but not in Ruby 2.1
5353
return val if val.frozen? || val.nil?
54-
val.transform_values!(&:freeze).freeze
54+
val.each { |_k, v| v.freeze }.freeze
5555
end
5656

5757
def current_auth_info

0 commit comments

Comments
 (0)