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)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#ctimeDate (readonly)

Returns:

  • (Date)


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

def ctime
  @ctime
end

#dependency_pathsString (readonly)

Returns:

  • (String)


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

def dependency_paths
  @dependency_paths
end

#file_pathString (readonly)

Returns:

  • (String)


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

def file_path
  @file_path
end

#mtimeDate (readonly)

Returns:

  • (Date)


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

def mtime
  @mtime
end

#sizeFixnum (readonly)

Returns:

  • (Fixnum)


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

def size
  @size
end

Instance Method Details

#==(other) ⇒ Bool

Parameters:

Returns:

  • (Bool)

Raises:

  • (AttributeError)


65
66
67
68
69
70
71
72
# 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) ⇒ Object

Parameters:

  • path (Array<String>, String)


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

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

#keep_dependencies!(paths) ⇒ Object

Parameters:

  • paths (Array<String>)


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

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