Class: Dashdog::Utils
- Inherits:
-
Object
- Object
- Dashdog::Utils
- Defined in:
- lib/dashdog/utils.rb
Class Method Summary collapse
- .deep_sort_hash(obj) ⇒ Object
- .diff(hash1, hash2) ⇒ Object
- .print_json(json) ⇒ Object
- .print_ruby(ruby, options = {}) ⇒ Object
- .print_yaml(yaml) ⇒ Object
Class Method Details
.deep_sort_hash(obj) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
8 9 10 11 12 13 14 |
# 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) ⇒ Object
31 32 33 |
# File 'lib/dashdog/utils.rb', line 31 def self.print_json(json) puts CodeRay.scan(json, :json).terminal end |
.print_ruby(ruby, options = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dashdog/utils.rb', line 23 def self.print_ruby(ruby, = {}) if [:color] puts CodeRay.scan(ruby, :ruby).terminal else puts ruby end end |
.print_yaml(yaml) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/dashdog/utils.rb', line 16 def self.print_yaml(yaml) CodeRay::Encoders::Terminal::TOKEN_COLORS[:key] = { self: "\e[32m", } puts CodeRay.scan(yaml, :yaml).terminal end |