Module: Atatus::Util

Defined in:
lib/atatus/util.rb,
lib/atatus/util/deep_dup.rb,
lib/atatus/util/throttle.rb,
lib/atatus/util/inflector.rb,
lib/atatus/util/lru_cache.rb,
lib/atatus/util/precision_validator.rb

Overview

rubocop:disable all

Defined Under Namespace

Modules: Inflector, PrecisionValidator Classes: DeepDup, LruCache, Throttle

Class Method Summary collapse

Class Method Details

.git_shaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
44
# File 'lib/atatus/util.rb', line 41

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

.hex_to_bits(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/atatus/util.rb', line 46

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

.micros(target = Time.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
# File 'lib/atatus/util.rb', line 32

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

.monotonic_microsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/atatus/util.rb', line 37

def self.monotonic_micros
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
end

.ms(micros) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/atatus/util.rb', line 24

def self.ms(micros)
  micros.to_f / 1_000
end

.reverse_merge!(first, *others) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
# File 'lib/atatus/util.rb', line 50

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

.truncate(value, max_length: 1024) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
# File 'lib/atatus/util.rb', line 56

def self.truncate(value, max_length: 1024)
  return unless value

  value = String(value)
  return value if value.length <= max_length

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

.us(ms) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
# File 'lib/atatus/util.rb', line 28

def self.us(ms)
  ms * 1_000
end