Sha256: 2973521403b0e7fdcf670b57321f9fe7c26366edfa7c0bf1fea6441ecf6537fd

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Epuber
  class Compiler
    class FileStat
      # @return [Date]
      #
      attr_reader :mtime

      # @return [Date]
      #
      attr_reader :ctime

      # @return [Fixnum]
      #
      attr_reader :size

      # @return [String]
      #
      attr_reader :file_path

      # @return [String]
      #
      attr_reader :dependency_paths

      # @param [String] path
      # @param [File::Stat] stat
      # @param [Bool] load_stats
      #
      def initialize(path, stat = nil, load_stats: true, dependency_paths: [])
        @file_path = path

        if load_stats
          begin
            stat ||= File.stat(path)
            @mtime = stat.mtime
            @ctime = stat.ctime
            @size = stat.size
          rescue StandardError
            # noop
          end
        end

        @dependency_paths = dependency_paths
      end

      # @param [Array<String>, String] path
      #
      def add_dependency!(path)
        @dependency_paths += Array(path)
        @dependency_paths.uniq!
      end

      # @param [Array<String>] paths
      #
      def keep_dependencies!(paths)
        to_delete = (dependency_paths - paths)
        @dependency_paths -= to_delete
      end

      # @param [FileStat] other
      #
      # @return [Bool]
      #
      def ==(other)
        raise AttributeError, "other must be class of #{self.class}" unless other.is_a?(FileStat)

        file_path == other.file_path &&
          size == other.size &&
          mtime == other.mtime &&
          ctime == other.ctime
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
epuber-0.11.1 lib/epuber/compiler/file_stat.rb
epuber-0.11.0 lib/epuber/compiler/file_stat.rb
epuber-0.10.3 lib/epuber/compiler/file_stat.rb
epuber-0.10.2 lib/epuber/compiler/file_stat.rb
epuber-0.10.1 lib/epuber/compiler/file_stat.rb
epuber-0.9.3 lib/epuber/compiler/file_stat.rb
epuber-0.9.2 lib/epuber/compiler/file_stat.rb
epuber-0.9.1 lib/epuber/compiler/file_stat.rb
epuber-0.9.0 lib/epuber/compiler/file_stat.rb
epuber-0.8.0 lib/epuber/compiler/file_stat.rb