Sha256: 06bb2a5cccefe0bfa6b5d35ae0d574313e0ba1040ab09b3360a057ec48187d3b

Contents?: true

Size: 939 Bytes

Versions: 51

Compression:

Stored size: 939 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

51 entries across 51 versions & 1 rubygems

Version Path
marty-14.3.0 lib/marty/diagnostic/packer.rb
marty-14.0.0 lib/marty/diagnostic/packer.rb
marty-13.0.2 lib/marty/diagnostic/packer.rb
marty-11.0.0 lib/marty/diagnostic/packer.rb
marty-10.0.3 lib/marty/diagnostic/packer.rb
marty-10.0.2 lib/marty/diagnostic/packer.rb
marty-10.0.0 lib/marty/diagnostic/packer.rb
marty-9.5.1 lib/marty/diagnostic/packer.rb
marty-9.5.0 lib/marty/diagnostic/packer.rb
marty-9.3.3 lib/marty/diagnostic/packer.rb
marty-9.3.2 lib/marty/diagnostic/packer.rb
marty-9.3.0 lib/marty/diagnostic/packer.rb
marty-8.5.0 lib/marty/diagnostic/packer.rb
marty-8.4.1 lib/marty/diagnostic/packer.rb
marty-8.3.1 lib/marty/diagnostic/packer.rb
marty-8.2.0 lib/marty/diagnostic/packer.rb
marty-8.0.0 lib/marty/diagnostic/packer.rb
marty-6.1.0 lib/marty/diagnostic/packer.rb
marty-5.2.0 other/marty/diagnostic/packer.rb
marty-5.1.4 other/marty/diagnostic/packer.rb