Sha256: 9cd4f4e488f77df49710ba7b26a21b0828838f936d850c49a4e7ef1673795c06

Contents?: true

Size: 1013 Bytes

Versions: 11

Compression:

Stored size: 1013 Bytes

Contents

class Hash
  def netzke_deep_map(&block)
    self.dup.tap do |h|
      h.each_pair do |k,v|
        h[k] = v.netzke_deep_map(&block) if v.respond_to?('netzke_deep_map')
      end
    end
  end

  def netzke_jsonify
    self.inject({}) do |h,(k,v)|
      new_key = if k.is_a?(Netzke::Core::JsonLiteral)
                  k
                elsif k.is_a?(String)
                  k.camelize(:lower)
                elsif k.is_a?(Symbol)
                  k.to_s.camelize(:lower).to_sym
                else
                  k
                end

      new_value = v.is_a?(Array) || v.is_a?(Hash) ? v.netzke_jsonify : v

      h.merge(new_key => new_value)
    end
  end

  # From http://rubyworks.github.com/facets
  def netzke_update_keys #:yield:
    if block_given?
      keys.each { |old_key| store(yield(old_key), delete(old_key)) }
    else
      to_enum(:netzke_update_keys)
    end
  end

  def netzke_literalize_keys
    netzke_update_keys{ |k| Netzke::Core::JsonLiteral.new(k.to_s) }
    self
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
netzke-core-0.12.2 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.12.1 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.12.0 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.12.0.rc1 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.12.0.beta lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.11.0 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.10.1 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.10.0 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.9.0 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.10.0.rc2 lib/netzke/core/ruby_ext/hash.rb
netzke-core-0.10.0.rc1 lib/netzke/core/ruby_ext/hash.rb