class FileManager

Public Class Methods

new() click to toggle source
# File lib/zarchitect/file_manager.rb, line 3
def initialize
  @from = FILEDIR # where user puts files
  @to = File.join(HTMLDIR, FILESDIR) # files in website dir tree

  @img = Array.new
  @audio = Array.new
  @video = Array.new
  @misc  = Array.new
end

Public Instance Methods

clean() click to toggle source
# File lib/zarchitect/file_manager.rb, line 59
def clean
  # remove all files in _html/files
  %x{rm -r _html/files/*} 
end
run() click to toggle source
# File lib/zarchitect/file_manager.rb, line 13
def run
  # iterate FROM
  Dir[ File.join(@from, '**', '*') ].reject do |fullpath|
    path = fullpath[(@from.length)..-1]
    realpath = File.join(@to, path) # path of new dir/symlink
    
    # dir handling / create copies in TO
    Util.mkdir(realpath) if File.directory?(fullpath)
    next if File.directory?(fullpath)
    # file handling
    # handle file types embedded in posts
    if Image.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as image file",
        GPI::CLU.check_option('v')
      @img.push ImageSet.new(path, fullpath, realpath)
    elsif Audio.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as audio file",
        GPI::CLU.check_option('v')
      @audio.push Audio.new(fullpath)
    elsif Video.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as video file",
        GPI::CLU.check_option('v')
      @video.push Video.new(fullpath)
    else
      GPI.print "processing #{fullpath} as any file",
        GPI::CLU.check_option('v')
      @misc.push MiscFile.new(fullpath)
    end
    # create symlink in _html/files to physical files _files (if process did
    # not abort)
    unless File.symlink?(realpath)
      rrealpath = File.join(Dir.getwd, fullpath)
      symlink(rrealpath, realpath)
    end

  end
end