Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move symbolize_keys to Propono namespace
* behaviour is quirky and conflicts with e.g. ActiveSupport implementation * retained Propono implementation rather than depend on yet another library, but don't mixin with Hash * change impact: anyone inheriting Hash#symbolise_keys from Propono and using elsewhere in their projects would need to decide to use another library for symbolize_keys, or use Propono::Utils.symbolize_keys explicitly
- Loading branch information
Showing
9 changed files
with
24 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Propono | ||
module Utils | ||
|
||
# Returns +hash+ with all primary and nested keys to string values symbolised | ||
# To avoid conflicts with ActiveSupport and other libraries that provide Hash symbolisation, | ||
# this method is kept within the Propono namespace and not mixed into Hash | ||
def self.symbolize_keys(hash) | ||
hash.inject({}) do |result, (key, value)| | ||
new_key = key.is_a?(String) ? key.to_sym : key | ||
new_value = value.is_a?(Hash) ? symbolize_keys(value) : value | ||
result[new_key] = new_value | ||
result | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters