Module: KafkaRestClient::Utils
- Defined in:
- lib/kafka_rest_client/utils.rb
Class Method Summary collapse
- .deep_stringify_keys(hash) ⇒ Object
-
.transform_hash(original, options = {}, &block) ⇒ Object
Courtersy of avdi Source gist.github.com/avdi/239567.
Class Method Details
.deep_stringify_keys(hash) ⇒ Object
17 18 19 20 21 |
# File 'lib/kafka_rest_client/utils.rb', line 17 def deep_stringify_keys(hash) transform_hash(hash, :deep => true) {|hash, key, value| hash[key.to_s] = value } end |
.transform_hash(original, options = {}, &block) ⇒ Object
Courtersy of avdi Source gist.github.com/avdi/239567
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/kafka_rest_client/utils.rb', line 5 def transform_hash(original, ={}, &block) original.inject({}){|result, (key,value)| value = if ([:deep] && Hash === value) transform_hash(value, , &block) else value end block.call(result,key,value) result } end |