class ASF::ICLAFiles

Common class for access to documents/iclas/ directory Only intended for use by secretary team

Public Class Methods

Dir?(name) click to toggle source

is the name a directory?

# File lib/whimsy/asf/documents.rb, line 74
def self.Dir?(name)
  listnames.include? name + '/'
end
listnames() click to toggle source

This returns the list of names in the top-level directory directory names are terminated by '/'

# File lib/whimsy/asf/documents.rb, line 93
  def self.listnames
    iclas = 'iclas'
    cache_dir = ASF::Config.get(:cache)
    # iclas.txt no longer updated by cronjob
    file, _ = ASF::SVN.listingNames(iclas, cache_dir)
    age = (Time.now - begin File.mtime(file) rescue 0 end).to_i
    if age > 600 # 5 minutes
      Wunderbar.warn "Updating listing #{file} #{age}"
      require 'whimsy/asf/rack'
      ASF::Auth.decode(env = {})
      filerev, svnrev = ASF::SVN.updatelisting(iclas, env.user, env.password, false, cache_dir)
      if filerev && svnrev # it worked
        FileUtils.touch file # last time it was checked
      else
        # raise IOError.new("Failed to fetch iclas.txt: #{svnrev}")
        Wunderbar.warn("User #{env.user}: failed to fetch iclas.txt: #{svnrev}")
      end
    end
    @@tag, list = ASF::SVN.getlisting(iclas, @@tag, false, false, cache_dir)
    if list # we have a new list
      # update the list cache
      @@list = list
      # clear the hash caches
      @@h_claRef = nil
      @@h_stem = nil
    end
    @@list
  end
end
matchStem(stem) click to toggle source

return a list of names matching stem.* Does not return directories

# File lib/whimsy/asf/documents.rb, line 80
def self.matchStem(stem)
  unless @@h_stem
    h_stem = Hash.new {|h, k| h[k] = []}
    listnames.map do |l|
      h_stem[l.split('.')[0]] << l unless l.end_with?('/')
    end
    @@h_stem = h_stem
  end
  @@h_stem[stem]
end
match_claRef(claRef) click to toggle source

search icla files to find match with claRef matches if the input matches the full name of a file or directory or it matches with an extension Returns the basename or nil if no match

# File lib/whimsy/asf/documents.rb, line 55
def self.match_claRef(claRef)
  unless @@h_claRef
    h_claRef = {}
    listnames.map do |l|
      # Match either full name (e.g. directory) or stem (e.g. name.pdf)
      if l.end_with? '/'
        h_claRef[l.chomp('/')] = l.chomp('/')
      elsif l.include?('.')
        h_claRef[l.split('.')[0]] = l
      else
        h_claRef[l] = l
      end
    end
    @@h_claRef = h_claRef
  end
  @@h_claRef[claRef]
end