Sha256: bb1cb9abb5f0fbef42d9b443e27338727f778a3830e103f069264be11fd476b4

Contents?: true

Size: 823 Bytes

Versions: 9

Compression:

Stored size: 823 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  module Util
    def self.nearest_minute(target = Time.now.utc)
      target - target.to_i % 60
    end

    def self.micros(target = Time.now)
      utc = target.utc
      utc.to_i * 1_000_000 + utc.usec
    end

    def self.git_sha
      sha = `git rev-parse --verify HEAD 2>&1`.chomp
      $? && $?.success? ? sha : nil
    end

    def self.hex_to_bits(str)
      str.hex.to_s(2).rjust(str.size * 4, '0')
    end

    def self.reverse_merge!(first, *others)
      others.reduce(first) do |curr, other|
        curr.merge!(other) { |_, _, new| new }
      end
    end

    def self.truncate(value, max_length: 1024)
      return unless value
      return value if value.length <= max_length

      value[0...(max_length - 1)] + '…'
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
elastic-apm-2.12.0 lib/elastic_apm/util.rb
elastic-apm-2.11.0 lib/elastic_apm/util.rb
elastic-apm-2.10.1 lib/elastic_apm/util.rb
elastic-apm-2.10.0 lib/elastic_apm/util.rb
elastic-apm-2.9.1 lib/elastic_apm/util.rb
elastic-apm-2.9.0 lib/elastic_apm/util.rb
elastic-apm-2.8.1 lib/elastic_apm/util.rb
elastic-apm-2.8.0 lib/elastic_apm/util.rb
elastic-apm-2.7.0 lib/elastic_apm/util.rb