Sha256: 881ed6f4d60e377da255b4912f9e87c3f5a2b2027f86fe159168f70a562b4e26

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

module Marty::Diagnostic; module Packer
  # expects a block that returns either a String or a Hash value and formats
  # it into a diagnostic info object.
  def pack include_ip=true
    begin
      data = yield
      info = case data
             when Hash
               is_valid_info?(data) ? {name.demodulize => data} :
                 data.each_with_object({}) do
                 |(key, value), hash|
                 case value
                 when Hash
                   raise "Invalid Diagnostic Info #{value}" unless
                     is_valid_info?(value)

                   hash[key] = value
                 else
                   hash[key] = create_info(value.to_s)
                 end
               end
             else
               {name.demodulize => create_info(data.to_s)}
             end
      include_ip ? {Node.my_ip => info} : info
    end
  end

  def create_info description, status=true, consistent=nil
    {
      'description' => description,
      '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

11 entries across 11 versions & 1 rubygems

Version Path
marty-1.2.9 other/marty/diagnostic/packer.rb
marty-1.2.8 other/marty/diagnostic/packer.rb
marty-1.2.7 other/marty/diagnostic/packer.rb
marty-1.2.6 other/marty/diagnostic/packer.rb
marty-1.2.5 other/marty/diagnostic/packer.rb
marty-1.2.4 other/marty/diagnostic/packer.rb
marty-1.2.3 other/marty/diagnostic/packer.rb
marty-1.2.2 other/marty/diagnostic/packer.rb
marty-1.2.1 lib/marty/diagnostic/packer.rb
marty-1.2.0 lib/marty/diagnostic/packer.rb
marty-1.1.9 lib/marty/diagnostic/packer.rb