Skip to content
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

Tech 4747 update contextual logger to normalize context keys to symbols #36

Conversation

yinonrousso
Copy link
Contributor

Jira Ticket

Description

Update contextual logger to normalize keys to symbols and warn on string keys

Gotchas

None

For the Code Reviewer:

  • The post deploy checks have been reviewed

end

def deep_key_has_string?(hash)
hash.keys.any? { |key| key.is_a? String } || hash.any? { |key, value| deep_key_has_string?(value) if value.is_a? Hash }
Copy link
Contributor

@ColinDKelley ColinDKelley Sep 11, 2020

Choose a reason for hiding this comment

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

@yinonrousso Our Ruby coding standards say to use parentheses around arguments unless it's a Domain Specific Language.

https://github.com/Invoca/style-guide/tree/master/ruby#omit-parentheses-around-parameters-for-methods-that-are-part-of-an-internal-dsl

Also, we only use trailing if/unless if it's a rare footnote that normally executes the preceding code.

https://github.com/Invoca/style-guide/tree/master/ruby#only-use-trailing-ifunless-when-they-are-rare-footnotes-that-can-be-ignored-in-the-usual-go-right-case

And the code is jammed up on one line. Here it is spread out a bit:

hash.keys.any? { |key| key.is_a?(String) } ||
   hash.any? { |key, value| (value.is_a?(Hash) && deep_key_has_string?(value) }

That's the same as:

hash.any? { |key, value| key.is_a?(String) } ||
   hash.any? { |key, value| (value.is_a?(Hash) && deep_key_has_string?(value) }

There's obviously no need to walk the hash twice!

hash.any? do |key, value|
  key.is_a?(String) } ||
    (value.is_a?(Hash) && deep_key_has_string?(value))
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I'll make the appropriate changes 👍

@yinonrousso yinonrousso self-assigned this Sep 14, 2020
@yinonrousso yinonrousso merged commit f84ad67 into master Sep 16, 2020
@yinonrousso yinonrousso deleted the TECH-4747_update_contextual_logger_to_normalize_context_keys_to_symbols branch September 16, 2020 14:50
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.

None yet

3 participants