module Qwik::AttachModule

Constants

DEFAULT_BACKUP
MAX

Public Instance Methods

another_file(num, filename) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 67
def another_file(num, filename)
  return "#{num}-#{filename}"       # '1-t.txt'
end
delete(filename, backup = DEFAULT_BACKUP) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 72
def delete(filename, backup = DEFAULT_BACKUP)
  fpath = path(filename)
  raise FileNotExist if ! fpath.exist?

  if backup         # Move to backup.
    dirpath = fpath.dirname
    basepath = fpath.basename
    moveto_basepath = ".._#{Time.now.to_i}_"+basepath
    moveto_path = dirpath + moveto_basepath
    FileUtils.mv(fpath.to_s, moveto_path.to_s)
  else
    fpath.unlink   # Real unilnk.
  end

  raise FailedToDelete if exist?(filename)

  return nil
end
each() { |a| ... } click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 103
def each
  return unless @attach_path.directory?
  self.list.each {|a|
    yield(a)
  }
end
exist?(filename) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 26
def exist?(filename)
  return path(filename).exist?
end
fput(filename, content, overwrite=nil, time=nil) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 55
def fput(filename, content, overwrite=nil, time=nil)        # obsolete
  # overwrite is always ignored.
  res = filename
  if exist?(filename)
    res, num = search_unused {|num| another_file(num, filename) }
  end

  put_internal(res, content, time)

  return res        # Return result.
end
get(filename) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 30
def get(filename)
  return path(filename).read
end
list() click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 91
def list
  return [] unless @attach_path.directory?
  ar = []
  @attach_path.each_entry {|file|
    next if file.directory?
    next if file.to_s == 'CVS'
    next if /\A\./ =~ file.to_s
    ar << Filename.decode(file.to_s)
  }
  return ar.sort!
end
overwrite(filename, content) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 34
def overwrite(filename, content)
  put(filename, content, true)
end
path(filename) click to toggle source

FIXME: AttachModule#path should be private.

# File vendor/qwik/lib/qwik/page-files.rb, line 21
def path(filename)
  @attach_path.check_directory
  return @attach_path + Filename.encode(filename)
end
put(filename, content, overwrite=nil, time=nil) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 38
def put(filename, content, overwrite=nil, time=nil)
  raise AlreadyExist if ! overwrite && exist?(filename)

  put_internal(filename, content, time)

  return nil
end
total() click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 46
def total
  t = 0
  self.each {|f|
    s = self.path(f).size?
    t += s if s
  }
  return t
end

Private Instance Methods

put_internal(filename, content, time=nil) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 112
def put_internal(filename, content, time=nil)
  path(filename).put(content)
  set_time(filename, time) if time
end
search_unused() { |num| ... } click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 123
def search_unused
  (1..MAX).each {|num|
    f = yield(num)
    return f, num if ! exist?(f)
  }
  raise 'MAX Exceed.'
end
set_time(filename, time) click to toggle source
# File vendor/qwik/lib/qwik/page-files.rb, line 117
def set_time(filename, time)
  time = Time.at(time) if time.is_a?(Integer)
  path(filename).utime(time, time)
end