123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::Performance::ConcurrentMonotonicTime

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, AutoCorrector, Base
Instance Chain:
self, Base
Inherits: Base
  • Object
Defined in: lib/rubocop/cop/performance/concurrent_monotonic_time.rb

Overview

Identifies places where Concurrent.monotonic_time can be replaced by Process.clock_gettime(Process::CLOCK_MONOTONIC).

Examples:

# bad
Concurrent.monotonic_time

# good
Process.clock_gettime(Process::CLOCK_MONOTONIC)

Constant Summary

Instance Method Summary

Instance Method Details

#on_send(node)

[ GitHub ]

  
# File 'lib/rubocop/cop/performance/concurrent_monotonic_time.rb', line 28

def on_send(node)
  return unless concurrent_monotonic_time?(node)

  optional_unit_parameter = ", #{node.first_argument.source}" if node.first_argument
  prefer = "Process.clock_gettime(Process::CLOCK_MONOTONIC#{optional_unit_parameter})"
  message = format(MSG, prefer: prefer, current: node.source)

  add_offense(node, message: message) do |corrector|
    corrector.replace(node, prefer)
  end
end