Class: ClWiki::Util
- Inherits:
-
Object
- Object
- ClWiki::Util
- Defined in:
- lib/cl_wiki/util.rb
Class Method Summary collapse
- .compare_read_times!(a, b) ⇒ Object
- .convert_to_native_path(path) ⇒ Object
- .dump_time(time) ⇒ Object
- .raise_if_mtime_not_equal(mtime_to_compare, file_name) ⇒ Object
Class Method Details
.compare_read_times!(a, b) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/cl_wiki/util.rb', line 10 def self.compare_read_times!(a, b) # ignore usec a = Time.new(a.year, a.month, a.day, a.hour, a.min, a.sec) b = Time.new(b.year, b.month, b.day, b.hour, b.min, b.sec) if a != b raise FileModifiedSinceRead, "File has been modified since it was last read. #{dump_time(a)} != #{dump_time(b)}" end end |
.convert_to_native_path(path) ⇒ Object
26 27 28 |
# File 'lib/cl_wiki/util.rb', line 26 def self.convert_to_native_path(path) path.gsub(%r{/}, ::File::SEPARATOR).gsub(/\\/, ::File::SEPARATOR) end |
.dump_time(time) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/cl_wiki/util.rb', line 19 def self.dump_time(time) String.new.tap do |s| s << time.to_s s << ".#{time.usec}" if time.respond_to?(:usec) end end |
.raise_if_mtime_not_equal(mtime_to_compare, file_name) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/cl_wiki/util.rb', line 3 def self.raise_if_mtime_not_equal(mtime_to_compare, file_name) # reading the instance .mtime appears to take Windows DST into account, # whereas the static File.mtime(filename) method does not current_mtime = ::File.open(file_name, &:mtime) compare_read_times!(mtime_to_compare, current_mtime) end |