Class: Rumbrl::Smash
- Inherits:
-
Object
- Object
- Rumbrl::Smash
- Defined in:
- lib/rumbrl/smash.rb
Overview
serializes & flattens hashes
Class Method Summary collapse
Class Method Details
.build_namespace(prev = '', cur = '') ⇒ Object
18 19 20 21 |
# File 'lib/rumbrl/smash.rb', line 18 def self.build_namespace(prev = '', cur = '') prev = "#{prev}_" unless prev.empty? "#{prev}#{cur}" end |
.flatten(target, namespace: '') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rumbrl/smash.rb', line 6 def self.flatten(target, namespace: '') target.each_with_object({}) do |(k, v), res| cur_namespace = build_namespace(namespace, k) if v.respond_to?(:to_log) res.update(flatten(v.to_log, namespace: cur_namespace)) else res.update(cur_namespace.to_sym => v) end end end |