Sha256: 1600901d30ce666d063ea4eb564cc459e00b90cc222c87453c4c3b88c527d6f7

Contents?: true

Size: 932 Bytes

Versions: 43

Compression:

Stored size: 932 Bytes

Contents

module Marty::Diagnostic; module Packer
  def pack include_ip=true
    info = process(yield)
    include_ip ? {Node.my_ip => info} : info
  end

  def process obj
    obj.is_a?(Hash) ? process_hash(obj) :
      {name.demodulize => create_info(obj.to_s)}
  end

  def process_hash data
    return {name.demodulize => data} if is_valid_info?(data)

    data.each_with_object({}) do
      |(k, v), h|
      if v.is_a?(Hash)
        raise "Invalid Diagnostic Info #{v}" unless is_valid_info?(v)
        h[k] = v
      else
        h[k] = create_info(v)
      end
    end
  end

  def create_info description, status=true, consistent=nil
    {
      'description' => description.to_s,
      'status'      => status,
      'consistent'  => consistent
    }
  end

  def is_valid_info? info
    info.keys.to_set == Set['description', 'status', 'consistent']
  end

  def error description
    create_info(description, false)
  end
end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
marty-2.5.2 other/marty/diagnostic/packer.rb
marty-2.5.1 other/marty/diagnostic/packer.rb
marty-2.5.0 other/marty/diagnostic/packer.rb
marty-2.4.9 other/marty/diagnostic/packer.rb
marty-2.4.8 other/marty/diagnostic/packer.rb
marty-2.4.7 other/marty/diagnostic/packer.rb
marty-2.4.6 other/marty/diagnostic/packer.rb
marty-2.4.5 other/marty/diagnostic/packer.rb
marty-2.4.4 other/marty/diagnostic/packer.rb
marty-2.4.3 other/marty/diagnostic/packer.rb
marty-2.4.2 other/marty/diagnostic/packer.rb
marty-2.4.1 other/marty/diagnostic/packer.rb
marty-2.4.0 other/marty/diagnostic/packer.rb
marty-2.3.15 other/marty/diagnostic/packer.rb
marty-2.3.14 other/marty/diagnostic/packer.rb
marty-2.3.13 other/marty/diagnostic/packer.rb
marty-2.3.12 other/marty/diagnostic/packer.rb
marty-2.3.11 other/marty/diagnostic/packer.rb
marty-2.3.10 other/marty/diagnostic/packer.rb
marty-2.3.9 other/marty/diagnostic/packer.rb