class Dashdog::Utils

Public Class Methods

deep_sort_hash(obj) click to toggle source
# File lib/dashdog/utils.rb, line 35
def self.deep_sort_hash(obj)
  case obj
  when Hash
    new_hash = {}

    obj.sort_by{|k, _| k.to_s }.each do |key, value|
      new_hash[key] = self.deep_sort_hash(value)
    end

    new_hash
  when Array
    obj.map do |value|
      self.deep_sort_hash(value)
    end
  else
    obj
  end
end
diff(hash1, hash2) click to toggle source
# File lib/dashdog/utils.rb, line 8
def self.diff(hash1, hash2)
  Diffy::Diff.new(
    JSON.pretty_generate(self.deep_sort_hash(hash1)) + "\n",
    JSON.pretty_generate(self.deep_sort_hash(hash2)) + "\n",
    :diff => '-u'
  ).to_s(:color)
end
print_json(json) click to toggle source
print_ruby(ruby, options = {}) click to toggle source
print_yaml(yaml) click to toggle source