-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- One less dependency to manage - Smaller deployment package for projects that depend on Consult - Replaces String#present? by converting values to string and then checking that length is greater than 0 (nil.to_s is an empty string) - Replaces Hash#deep_symbolize_keys! and Hash#deep_merge with their ActiveSupport implementations
- Loading branch information
1 parent
9a966c9
commit ed555e6
Showing
2 changed files
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# ActiveSupport's corresponding methods | ||
# - https://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/hash | ||
module HashExtension | ||
def deep_symbolize_keys!(object = self) | ||
case object | ||
when Hash | ||
object.keys.each do |key| | ||
value = object.delete key | ||
object[key.to_sym] = deep_symbolize_keys! value | ||
end | ||
object | ||
when Array | ||
object.map! { |e| deep_symbolize_keys! e } | ||
else | ||
object | ||
end | ||
end | ||
|
||
def deep_merge(other_hash, &block) | ||
merge(other_hash) do |key, this_val, other_val| | ||
if this_val.is_a?(Hash) && other_val.is_a?(Hash) | ||
this_val.deep_merge other_val, &block | ||
elsif block_given? | ||
block.call key, this_val, other_val | ||
else | ||
other_val | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hash.send(:include, HashExtension) |