class Epuber::Compiler::FileStat

Attributes

ctime[R]

@return [Date]

dependency_paths[R]

@return [String]

file_path[R]

@return [String]

mtime[R]

@return [Date]

size[R]

@return [Fixnum]

Public Class Methods

new(path, stat = nil, load_stats: true, dependency_paths: []) click to toggle source

@param [String] path @param [File::Stat] stat @param [Bool] load_stats

# File lib/epuber/compiler/file_stat.rb, line 30
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

Public Instance Methods

==(other) click to toggle source

@param [FileStat] other

@return [Bool]

# File lib/epuber/compiler/file_stat.rb, line 65
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
add_dependency!(path) click to toggle source

@param [Array<String>, String] path

# File lib/epuber/compiler/file_stat.rb, line 49
def add_dependency!(path)
  @dependency_paths += Array(path)
  @dependency_paths.uniq!
end
keep_dependencies!(paths) click to toggle source

@param [Array<String>] paths

# File lib/epuber/compiler/file_stat.rb, line 56
def keep_dependencies!(paths)
  to_delete = (dependency_paths - paths)
  @dependency_paths -= to_delete
end