Class: Epuber::Compiler::FileStat

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/compiler/file_stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, stat = nil, load_stats: true, dependency_paths: []) ⇒ FileStat

Returns a new instance of FileStat.

Parameters:

  • path (String)
  • stat (File::Stat) (defaults to: nil)
  • load_stats (Bool) (defaults to: true)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/epuber/compiler/file_stat.rb', line 31

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

Instance Attribute Details

#ctimeDate (readonly)

Returns:

  • (Date)


13
14
15
# File 'lib/epuber/compiler/file_stat.rb', line 13

def ctime
  @ctime
end

#dependency_pathsString (readonly)

Returns:

  • (String)


25
26
27
# File 'lib/epuber/compiler/file_stat.rb', line 25

def dependency_paths
  @dependency_paths
end

#file_pathString (readonly)

Returns:

  • (String)


21
22
23
# File 'lib/epuber/compiler/file_stat.rb', line 21

def file_path
  @file_path
end

#mtimeDate (readonly)

Returns:

  • (Date)


9
10
11
# File 'lib/epuber/compiler/file_stat.rb', line 9

def mtime
  @mtime
end

#sizeFixnum (readonly)

Returns:

  • (Fixnum)


17
18
19
# File 'lib/epuber/compiler/file_stat.rb', line 17

def size
  @size
end

Instance Method Details

#==(other) ⇒ Bool

Parameters:

Returns:

  • (Bool)

Raises:

  • (AttributeError)


66
67
68
69
70
71
72
73
# File 'lib/epuber/compiler/file_stat.rb', line 66

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) ⇒ Object

Parameters:

  • path (Array<String>, String)


50
51
52
53
# File 'lib/epuber/compiler/file_stat.rb', line 50

def add_dependency!(path)
  @dependency_paths += Array(path)
  @dependency_paths.uniq!
end

#keep_dependencies!(paths) ⇒ Object

Parameters:

  • paths (Array<String>)


57
58
59
60
# File 'lib/epuber/compiler/file_stat.rb', line 57

def keep_dependencies!(paths)
  to_delete = (dependency_paths - paths)
  @dependency_paths -= to_delete
end