instance method max_mtime

Ruby on Rails 8.1.2

Since v4.0.13 Private

Available in: v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

max_mtime(paths)

This method returns the maximum mtime of the files in paths, or nil if the array is empty.

Files with a mtime in the future are ignored. Such abnormal situation can happen for example if the user changes the clock by hand. It is healthy to consider this edge case because with mtimes in the future reloading is not triggered.

Parameters

paths req
Source
# File activesupport/lib/active_support/file_update_checker.rb, line 125
      def max_mtime(paths)
        time_now = Time.at(0, Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond), :nanosecond)
        max_mtime = nil

        # Time comparisons are performed with #compare_without_coercion because
        # AS redefines these operators in a way that is much slower and does not
        # bring any benefit in this particular code.
        #
        # Read t1.compare_without_coercion(t2) < 0 as t1 < t2.
        paths.each do |path|
          mtime = File.mtime(path)

          next if time_now.compare_without_coercion(mtime) < 0

          if max_mtime.nil? || max_mtime.compare_without_coercion(mtime) < 0
            max_mtime = mtime
          end
        end

        max_mtime
      end

Defined in activesupport/lib/active_support/file_update_checker.rb line 125 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::FileUpdateChecker

Type at least 2 characters to search.

↑↓ navigate · open · esc close