Class: Lumin::SourceSnapshot
- Inherits:
-
Data
- Object
- Data
- Lumin::SourceSnapshot
- Defined in:
- lib/lumin/source_snapshot.rb
Defined Under Namespace
Classes: ChangedError
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Attribute Details
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint
4 5 6 |
# File 'lib/lumin/source_snapshot.rb', line 4 def fingerprint @fingerprint end |
#source ⇒ Object (readonly)
Returns the value of attribute source
4 5 6 |
# File 'lib/lumin/source_snapshot.rb', line 4 def source @source end |
Class Method Details
.fingerprint(path_or_stat) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lumin/source_snapshot.rb', line 18 def self.fingerprint(path_or_stat) stat = path_or_stat.is_a?(File::Stat) ? path_or_stat : File.stat(path_or_stat) [ stat.size, stat.mtime.to_i, stat.mtime.nsec, stat.ctime.to_i, stat.ctime.nsec, stat.ino ].freeze end |
.read(path) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/lumin/source_snapshot.rb', line 7 def self.read(path) File.open(path, "rb") do |file| before = fingerprint(file.stat) source = file.read after = fingerprint(file.stat) raise ChangedError, "#{path} changed while it was being read" unless before == after new(source: source, fingerprint: after) end end |