Module: LcpRuby::HashUtils
- Defined in:
- lib/lcp_ruby/hash_utils.rb
Constant Summary collapse
- SOURCE_LOC_KEY_RE =
Recursively strips i18n_check Phase 3a internal keys (‘_*_source_loc`, `_source_loc`) from a deep hash structure. Used by Definition classes so their public `*_config` accessors look identical regardless of whether the data came from a DSL builder (which adds source-locs) or YAML (which doesn’t). Iterator methods access the unsanitized raw hash separately for source-line reporting.
/\A_.*source_loc\z/.freeze
Class Method Summary collapse
-
.stringify_deep(value) ⇒ Object
Recursively stringify Hash keys and Symbol values.
- .strip_source_locs(value) ⇒ Object
Class Method Details
.stringify_deep(value) ⇒ Object
Recursively stringify Hash keys and Symbol values. Recurses into Arrays. Passes through primitives unchanged.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lcp_ruby/hash_utils.rb', line 5 def self.stringify_deep(value) case value when Proc stringify_deep(Dsl::ConditionBuilder.build(&value)) when Hash value.transform_keys(&:to_s).transform_values { |v| stringify_deep(v) } when Symbol value.to_s when Array value.map { |v| stringify_deep(v) } else value end end |
.strip_source_locs(value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lcp_ruby/hash_utils.rb', line 28 def self.strip_source_locs(value) case value when Hash value.each_with_object({}) do |(k, v), out| next if k.is_a?(String) && k.match?(SOURCE_LOC_KEY_RE) out[k] = strip_source_locs(v) end when Array value.map { |v| strip_source_locs(v) } else value end end |