Sha256: 2f2742c4064029ec22620f44ca81b5640e7ea9c42de6158b49dadd2eef8b2fec

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8
# 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
            # 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

15 entries across 15 versions & 1 rubygems

Version Path
epuber-0.6.0 lib/epuber/compiler/file_stat.rb
epuber-0.5.7 lib/epuber/compiler/file_stat.rb
epuber-0.5.6 lib/epuber/compiler/file_stat.rb
epuber-0.5.5 lib/epuber/compiler/file_stat.rb
epuber-0.5.4 lib/epuber/compiler/file_stat.rb
epuber-0.5.3 lib/epuber/compiler/file_stat.rb
epuber-0.5.2 lib/epuber/compiler/file_stat.rb
epuber-0.5.1 lib/epuber/compiler/file_stat.rb
epuber-0.5.0 lib/epuber/compiler/file_stat.rb
epuber-0.5.0.beta.5 lib/epuber/compiler/file_stat.rb
epuber-0.5.0.beta.4 lib/epuber/compiler/file_stat.rb
epuber-0.5.0.beta.3 lib/epuber/compiler/file_stat.rb
epuber-0.5.0.beta.2 lib/epuber/compiler/file_stat.rb
epuber-0.5.0.beta lib/epuber/compiler/file_stat.rb
epuber-0.4.0 lib/epuber/compiler/file_stat.rb