class Object
Constants
- CONFIG_KEYS
`jq 'keys'` used on a full configuration to quickly extract keys
Public Instance Methods
deep_stringify_keys(hash)
click to toggle source
# File lib/extensions/marathon/app.rb, line 52 def deep_stringify_keys(hash) transform_hash(hash, :deep => true) {|hash, key, value| hash[key.to_s] = value } end
filtered_info()
click to toggle source
# File lib/extensions/marathon/app.rb, line 31 def filtered_info # Remove the all non-configuration keys sort_hash(deep_stringify_keys(info).reject { |key, value| !CONFIG_KEYS.include?(key) }) end
filtered_info_to_json()
click to toggle source
# File lib/extensions/marathon/app.rb, line 36 def filtered_info_to_json JSON.pretty_generate(filtered_info) end
info_to_json()
click to toggle source
# File lib/extensions/marathon/app.rb, line 40 def info_to_json JSON.pretty_generate(sort_hash(info)) end
slice_hash(hash, *keys)
click to toggle source
# File lib/extensions/marathon/app.rb, line 58 def slice_hash(hash, *keys) transform_hash(hash, :deep => false) {|hash, key, value| hash[key] = value if keys.include?(key) } end
sort_hash(h)
click to toggle source
# File lib/extensions/marathon/app.rb, line 64 def sort_hash(h) {}.tap do |h2| h.sort.each do |k,v| h2[k] = v.is_a?(Hash) ? sort_hash(v) : v end end end
transform_hash(original, options={}, &block)
click to toggle source
# File lib/extensions/marathon/app.rb, line 72 def transform_hash(original, options={}, &block) original.inject({}){|result, (key,value)| value = if (options[:deep] && Hash === value) transform_hash(value, options, &block) else value end block.call(result,key,value) result } end
write_to_file(file)
click to toggle source
# File lib/extensions/marathon/app.rb, line 44 def write_to_file(file) File.open(file, 'w') do |f| f.write(filtered_info_to_json) end end