Class: ClWiki::Util
- Inherits:
-
Object
- Object
- ClWiki::Util
- Defined in:
- lib/cl_wiki/file.rb
Class Method Summary collapse
- .compare_read_times!(a, b) ⇒ Object
- .convertToNativePath(path) ⇒ Object
- .dump_time(time) ⇒ Object
- .raiseIfMTimeNotEqual(mtime_to_compare, file_name) ⇒ Object
Class Method Details
.compare_read_times!(a, b) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/cl_wiki/file.rb', line 169 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 |
.convertToNativePath(path) ⇒ Object
185 186 187 188 189 |
# File 'lib/cl_wiki/file.rb', line 185 def self.convertToNativePath(path) newpath = path.gsub(/\//, ::File::SEPARATOR) newpath = newpath.gsub(/\\/, ::File::SEPARATOR) return newpath end |
.dump_time(time) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/cl_wiki/file.rb', line 178 def self.dump_time(time) ''.tap do |s| s << "#{time}" s << ".#{time.usec}" if time.respond_to?(:usec) end end |
.raiseIfMTimeNotEqual(mtime_to_compare, file_name) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/cl_wiki/file.rb', line 160 def self.raiseIfMTimeNotEqual(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) do |f| f.mtime end compare_read_times!(mtime_to_compare, current_mtime) end |