class Qwik::PageRRefs

Public Class Methods

new(site_dir, key) click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 15
def initialize(site_dir, key)
  @rref_file = site_dir.path+"#{key}.rrefs"

  # fix me!
  # the mutex works only in a process
  # wiki server process is the process to update rrefs
  # ml-server is not supposed to update rrefs
  @lock = Mutex.new
end

Public Instance Methods

add(key) click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 46
def add(key)
  @lock.synchronize {
    f = File.open(@rref_file,"a")
    f.puts key
    f.close
  }
end
delete(key) click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 38
def delete(key)
  @lock.synchronize {
    rrefs = self.get
    rrefs = rrefs.map {|r| r if r.chomp != key }.to_s
    @rref_file.path.put(rrefs)
  }
end
each() { |chomp| ... } click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 59
def each
  return unless self.exist?
  # key might be deleted in the loop
  keys = self.get
  keys.each {|a|
    yield(a.chomp)
  }
end
exist?() click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 25
def exist?
  FileTest.exists?(@rref_file)
end
get() click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 29
def get
  if self.exist?
    rrefs = File.open(@rref_file).read
    return rrefs
  else
    return ""
  end
end
put(keys) click to toggle source
# File vendor/qwik/lib/qwik/page-rrefs.rb, line 54
def put(keys)
  rrefs = keys.join($/) + $/
  @rref_file.path.put(rrefs)
end