Sha256: bce1fb1f70855572f8b870db7f3af252d850f7201b8cb637ed12257d1d066149

Contents?: true

Size: 657 Bytes

Versions: 12

Compression:

Stored size: 657 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 Coprl::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

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.11 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.10 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.9 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.8 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.7 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.6 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.5 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.4 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.3 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.2 lib/coprl/presenters/web_client/helpers/expand_hash.rb
coprl-3.0.0.beta.1 lib/coprl/presenters/web_client/helpers/expand_hash.rb