class QuickML::GroupDB

Constants

PAGENAME

FILENAME = {

:Members          => ',members',
:Count            => ',count',
:Config           => ',config',
:Charset          => ',charset',
:Alerted          => ',alerted',
:Forward          => ',forward',
:Permanent        => ',permanent',
:Unlimited        => ',unlimited',
:WaitingMembers   => ',waiting-members',
:WaitingMessage   => ',waiting-message',

}

Public Class Methods

new(sites_dir, group_name) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 37
def initialize(sites_dir, group_name)
  @sites_dir = sites_dir
  @group_name = group_name
  @site = nil
  get_dirpath.mkpath        # Make a new directory here.
end

Public Instance Methods

add(s, content) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 142
    def add(s, content)
#      f = get_filepath(s)
#      f.add(content)

      pagename = get_pagename(s)
      page = @site[pagename]
      page = @site.create(pagename) if page.nil?
      page.add(content)
    end
delete(s) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 152
    def delete(s)
      return if ! exist?(s)
#      f = get_filepath(s)
#      f.unlink

      pagename = get_pagename(s)
      page = @site[pagename]
      @site.delete(pagename) if page
    end
exist?(s) click to toggle source

read

# File vendor/qwik/lib/qwik/group-db.rb, line 59
    def exist?(s)
      #sync(s)

#      f = get_filpath(s)
#      return true if f.exist?

      pagename = get_pagename(s)
      page = @site[pagename]
      return true if page

      return false
    end
get(s) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 77
    def get(s)  # with sync.
      #sync(s)

#      file_content = nil
#      f = get_filepath(s)
#      file_content = f.read if f.exist?

      page_content = nil
      pagename = get_pagename(s)
      page = @site[pagename]
      page_content = page.get if page
      return page_content

      # Both is nil.
#      return nil if file_content.nil? && page_content.nil?     # Do nothing.

#      fmt = file_mtime(s)
#      pmt = page_mtime(s)

      # File is exist, but the page is not exist.
#      if file_content && page_content.nil?
#       page = @site.create(pagename)
#       page.put_with_time(file_content, fmt)
#       # FIXME: delete file?
#       return file_content
#      end

      # File is not exist, but page is exist.
#      if file_content.nil? && page_content
#       # Do not create file.
#       #f.put(page_content)
#       #f.utime(pmt, pmt)
#       return page_content
#      end

      # Both exist.
#      if file_content == page_content
#       return page_content
#      end

#      if fmt < pmt     # The page is new.
#       f.put(page_content)
#       begin
#         f.utime(pmt, pmt)
#       rescue
#         p 'error to set time'
#       end
#       return page_content
#      end

#      page.put_with_time(file_content, fmt)
#      return file_content
    end
last_article_time() click to toggle source

the mtime of the newest file in the directory

# File vendor/qwik/lib/qwik/group-db.rb, line 163
    def last_article_time
      max = nil
      dir = get_dirpath
      dir.each_entry {|f|
        fs = f.to_s

        next if /\A\./ =~ fs ||
#         /,config/ =~ fs ||
          /_GroupConfig.txt/ =~ fs ||
#         /,charset/ =~ fs ||
          /_GroupCharset.txt/ =~ fs

        file = dir+f
        mt = file.mtime
        if max.nil? || max < mt
          max = mt 
        end
      }
      return max || Time.now
    end
mtime(s) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 72
    def mtime(s)
#      return [file_mtime(s), page_mtime(s)].max
      return page_mtime(s)
    end
put(s, content) click to toggle source

write

# File vendor/qwik/lib/qwik/group-db.rb, line 132
    def put(s, content)
#      f = get_filepath(s)
#      f.put(content)

      pagename = get_pagename(s)
      page = @site[pagename]
      page = @site.create(pagename) if page.nil?
      page.put(content)
    end
set_site(site) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 44
def set_site(site)
  @site = site
end

Private Instance Methods

get_dirpath() click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 190
def get_dirpath
  return "#{@sites_dir}/#{@group_name}".path
end
get_pagename(symbol) click to toggle source
# File vendor/qwik/lib/qwik/group-db.rb, line 186
def get_pagename(symbol)
  return PAGENAME[symbol]
end
page_mtime(s) click to toggle source

def get_filepath(symbol)

dir = get_dirpath
base = FILENAME[symbol]
return nil if base.nil?
return dir+base

end

def file_mtime(s)

f = get_filepath(s)
return f.mtime if f.exist?
return Time.at(0)

end

# File vendor/qwik/lib/qwik/group-db.rb, line 209
def page_mtime(s)
  pagename = get_pagename(s)
  page = @site[pagename]
  return page.mtime if page
  return Time.at(0)
end