Sha256: 5aff8fc6c6dc506ff9dd27098dde08929b851eb36fd2d88e363b103f4316a09f

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Guard
  class Depend
    class Detect
      attr_reader :output_paths

      def initialize(output_paths = nil)
        @output_paths = output_paths
      end

      def out_of_date?(paths = [])
        paths = paths || []
        return false if paths.empty?

        outdated = check(paths, output)
        UI.debug("#{output.join(', ')} is not outdated with regard to #{paths.join(', ')}") unless outdated

        outdated
      end

      private
      def output
        paths = output_paths
        paths = output_paths.call if output_paths.respond_to?(:call)

        [paths].flatten.reject(&:nil?)
      end

      def check(input, output)
        input = input.max_by { |f| input_mtime(f) }
        output = output.min_by { |f| output_mtime(f) }

        input_mtime = input_mtime(input)
        output_mtime = output_mtime(output)

        UI.debug("Newest input file:  #{input_mtime} #{input}")
        UI.debug("Oldest output file: #{output_mtime} #{output}")

        return input_mtime > output_mtime
      end

      def input_mtime(file)
        return Time.new(9999, 12, 31) unless File.readable?(file)
        File.mtime(file)
      end

      def output_mtime(file)
        return Time.new(0, 1, 1) unless File.readable?(file)
        File.mtime(file)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-depend-0.1.0 lib/guard/depend/detect.rb