Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket_rest_api/core_ext/hash.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#all_keysObject

:nodoc:



41
42
43
44
45
46
47
48
49
50
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 41

def all_keys # :nodoc:
  keys = self.keys
  keys.each do |key|
    if self[key].is_a?(Hash)
      keys << self[key].all_keys.compact.flatten
      next
    end
  end
  keys.flatten
end

#has_deep_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 54

def has_deep_key?(key)
  all_keys.include? key
end

#serializeObject

:nodoc:



35
36
37
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 35

def serialize # :nodoc:
  map { |key, val| [key, val].join('=') }.join('&')
end

#symbolize_keysObject

:nodoc:



4
5
6
7
8
9
10
11
12
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 4

def symbolize_keys  # :nodoc:
  each_with_object({}) do |(key, value), hash|
    hash[(begin
            key.to_sym
          rescue StandardError
            key
          end) || key] = value
  end
end

#symbolize_keys!Object

:nodoc:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 16

def symbolize_keys! # :nodoc:
  hash = symbolize_keys
  hash.each do |key, val|
    hash[key] = case val
                when Hash
                  val.symbolize_keys!
                when Array
                  val.map do |item|
                    item.is_a?(Hash) ? item.symbolize_keys! : item
                  end
                else
                  val
                end
  end
  hash
end