Class: Epuber::Compiler::FileStat
- Inherits:
-
Object
- Object
- Epuber::Compiler::FileStat
- Defined in:
- lib/epuber/compiler/file_stat.rb
Instance Attribute Summary collapse
- #ctime ⇒ Date readonly
- #dependency_paths ⇒ String readonly
- #file_path ⇒ String readonly
- #mtime ⇒ Date readonly
- #size ⇒ Fixnum readonly
Instance Method Summary collapse
- #==(other) ⇒ Bool
- #add_dependency!(path) ⇒ Object
-
#initialize(path, stat = nil, load_stats: true, dependency_paths: []) ⇒ FileStat
constructor
A new instance of FileStat.
- #keep_dependencies!(paths) ⇒ Object
Constructor Details
#initialize(path, stat = nil, load_stats: true, dependency_paths: []) ⇒ FileStat
Returns a new instance of FileStat.
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
#ctime ⇒ Date (readonly)
12 13 14 |
# File 'lib/epuber/compiler/file_stat.rb', line 12 def ctime @ctime end |
#dependency_paths ⇒ String (readonly)
24 25 26 |
# File 'lib/epuber/compiler/file_stat.rb', line 24 def dependency_paths @dependency_paths end |
#file_path ⇒ String (readonly)
20 21 22 |
# File 'lib/epuber/compiler/file_stat.rb', line 20 def file_path @file_path end |
#mtime ⇒ Date (readonly)
8 9 10 |
# File 'lib/epuber/compiler/file_stat.rb', line 8 def mtime @mtime end |
#size ⇒ Fixnum (readonly)
16 17 18 |
# File 'lib/epuber/compiler/file_stat.rb', line 16 def size @size end |
Instance Method Details
#==(other) ⇒ Bool
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
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
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 |