Sha256: 8fd9d4255f9371cdd97fc4cef1145d61a91112aae3a4bc3693c52699fd0f229e

Contents?: true

Size: 656 Bytes

Versions: 6

Compression:

Stored size: 656 Bytes

Contents

# Expands a hash ensuring all values are hash's
# POM object models expand to a hash using :to_hash
# JSON is serialized in as recursive OpenStruct's, they need special expansion logic.
module Voom::Presenters::WebClient::Helpers
  module ExpandHash
    def expand_hash(h)
      HashExt::Traverse.traverse(h.to_h) do |k,v|
        if !v.is_a?(Array) && v.respond_to?(:to_h)
          v = v.is_a?(OpenStruct) ? expand_hash(v.to_h) : v.to_h
        elsif v.is_a?(Array)
          v = v.map {|v| v.is_a?(OpenStruct) ? expand_hash(v.to_h) : v}
        elsif v.respond_to?(:to_hash)
          v = v.to_hash
        end
        [k,v]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
voom-presenters-2.1.2 lib/voom/presenters/web_client/helpers/expand_hash.rb
voom-presenters-2.1.0 lib/voom/presenters/web_client/helpers/expand_hash.rb
voom-presenters-2.0.3 lib/voom/presenters/web_client/helpers/expand_hash.rb
voom-presenters-2.0.2 lib/voom/presenters/web_client/helpers/expand_hash.rb
voom-presenters-2.0.1 lib/voom/presenters/web_client/helpers/expand_hash.rb
voom-presenters-2.0.0 lib/voom/presenters/web_client/helpers/expand_hash.rb