Class: ClWiki::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/cl_wiki/file.rb

Class Method Summary collapse

Class Method Details

.compare_read_times!(a, b) ⇒ Object



192
193
194
195
196
197
198
199
# File 'lib/cl_wiki/file.rb', line 192

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



208
209
210
# File 'lib/cl_wiki/file.rb', line 208

def self.convert_to_native_path(path)
  path.gsub(%r{/}, ::File::SEPARATOR).gsub(/\\/, ::File::SEPARATOR)
end

.dump_time(time) ⇒ Object



201
202
203
204
205
206
# File 'lib/cl_wiki/file.rb', line 201

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



185
186
187
188
189
190
# File 'lib/cl_wiki/file.rb', line 185

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