Sha256: 0f0a79e1dc74a5666feb5a7b803be1bed5a9e62e2ed16af1afcf9b68ef84d61e

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

module Vitals::Formats
  class HostLastFormat
    attr_accessor :environment
    attr_accessor :host
    attr_accessor :facility

    def initialize(environment:'development', facility:'default', host:'localhost')
      @environment = environment
      @facility = facility
      @host = host
      @host =  Vitals::Utils.normalize_metric(host).freeze if @host
      @prefix = [environment, facility].compact.map{|m| Vitals::Utils.normalize_metric(m) }
                                       .join(Vitals::Utils::SEPARATOR).freeze
      @prefix_with_host = [environment, facility, @host].compact.map{|m| Vitals::Utils.normalize_metric(m) }
                                       .join(Vitals::Utils::SEPARATOR).freeze
    end

    def format(m)
      return @prefix_with_host if (m.nil? || m.empty?)
      # TODO optimize by building a renderer function (inlining this) in the initializer.
      # see https://github.com/evanphx/benchmark-ips/blob/master/lib/benchmark/ips/job/entry.rb#L63
      [@prefix, Vitals::Utils.normalize_metric(m), @host].reject{|s| s.nil? || s.empty? }.join(Vitals::Utils::SEPARATOR)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vitals-0.12.0 lib/vitals/formats/host_last_format.rb
vitals-0.11.1 lib/vitals/formats/host_last_format.rb
vitals-0.11.0 lib/vitals/formats/host_last_format.rb
vitals-0.10.1 lib/vitals/formats/host_last_format.rb
vitals-0.10.0 lib/vitals/formats/host_last_format.rb
vitals-0.9.1 lib/vitals/formats/host_last_format.rb
vitals-0.9.0 lib/vitals/formats/host_last_format.rb
vitals-0.8.1 lib/vitals/formats/host_last_format.rb
vitals-0.8.0 lib/vitals/formats/host_last_format.rb
vitals-0.7.0 lib/vitals/formats/host_last_format.rb
vitals-0.6.0 lib/vitals/formats/host_last_format.rb
vitals-0.5.0 lib/vitals/formats/host_last_format.rb
vitals-0.4.0 lib/vitals/formats/host_last_format.rb
vitals-0.3.0 lib/vitals/formats/host_last_format.rb