class LuigiInternal

implements everything not exposed to the outside TODO: make this all private

Public Instance Methods

_new_project_folder(name) click to toggle source

creates new project_dir and project_file

# File lib/luigi_internal.rb, line 64
def _new_project_folder(name)
  unless check_dir(:working)
    @logger.info(File.exists? @dirs[:working])
    @logger.info "missing working directory!"
    return false
  end

  #  check of existing project with the same name
  folder = get_project_folder(name, :working)
  unless folder
    FileUtils.mkdir File.join @dirs[:working], name
    return get_project_folder(name, :working)
  else
    @logger.info "#{folder} already exists"
    return false
  end
end
check_dir(dir) click to toggle source

Checks the existens of one of the three basic dirs. dir can be either :storage, :working or :archive and also :templates

# File lib/luigi_internal.rb, line 36
def check_dir(dir)
  File.exists? @dirs[dir]
end
check_dirs() click to toggle source

Checks the existens of every thing required

# File lib/luigi_internal.rb, line 42
def check_dirs
  check_dir :storage and
  check_dir :working and
  check_dir :archive and
  check_dir :templates
end
get_project_file_path(name, dir=:working, year=Date.today.year) click to toggle source

derives path to project file from name there may only be one @file_extension file per project folder

untested

# File lib/luigi_internal.rb, line 87
def get_project_file_path(name, dir=:working, year=Date.today.year)
  name = ShellSanitizer.process    name
  name = ShellSanitizer.clean_path name

  folder = get_project_folder(name, dir, year)
  if folder
    files = Dir.glob File.join folder, "*#{@file_extension}"
    warn "ambiguous amount of #{@file_extension} files in #{folder}" if files.length > 1
    warn "no #{@file_extension} files in #{folder}" if files.length < 1
    return files[0]
  end
  @logger.info "NO FOLDER get_project_folder(name = #{name}, dir = #{dir}, year = #{year})"
  return false
end
init_dirs() click to toggle source
# File lib/luigi_internal.rb, line 22
def init_dirs
  @dirs = {}
  if @settings.dirs.storage?
    @dirs[:storage]   = File.expand_path(File.join(@settings.path, @settings['dirs']['storage']))
    @dirs[:working]   = File.join @dirs[:storage], @settings.dirs.working
    @dirs[:archive]   = File.join @dirs[:storage], @settings.dirs.archive
    @dirs[:templates] = File.join @dirs[:storage], @settings.dirs.templates
  end
end
init_logger() click to toggle source
# File lib/luigi_internal.rb, line 15
def init_logger
  @logger = Logger.new(STDERR)
  @logger.level = Logger::ERROR
  @logger.error "need a project_class" if @project_class.nil?
  @logger.progname = "LUIGI"
end
list_project_files_all() click to toggle source

list projects lists project files

# File lib/luigi_internal.rb, line 178
def list_project_files_all
  working = list_project_files_working
  archive = []
  map_archive_years.keys.each{|year|
    archive += list_project_files_archive(year)
  }
  return ( archive + working )
end
list_project_files_archive(year = Date.today.year) click to toggle source

lists project files from archive directory

# File lib/luigi_internal.rb, line 171
def list_project_files_archive(year = Date.today.year)
  map_project_files_archive(year).values
end
list_project_files_working() click to toggle source

lists project files from working directory

# File lib/luigi_internal.rb, line 166
def list_project_files_working()
  map_project_files_working.values
end
load_templates() click to toggle source

read the templates directory and cache paths

# File lib/luigi_internal.rb, line 50
def load_templates
  return false unless check_dir :templates
  #files = Dir.glob File.join @dirs[:templates] , ?*
  files = Dir.glob File.join(@dirs[:templates], "*{#{@file_extension}.erb,#{@file_extension}}")
  @templates =  {}
  files.each{|file|
    name = File.basename file.split(?.)[0]
    @templates[name.to_sym] = file
  }
  return true
end
map_archive_years() click to toggle source

returns map of years to archive folders

# File lib/luigi_internal.rb, line 153
def map_archive_years
  map = {}
  Dir.glob(File.join @dirs[:archive], "/*").each{|path|
    map[File.basename path] = path
  }
  return map
end
map_project_files(dir = :working, year=Date.today.year) click to toggle source

maps project names to files

# File lib/luigi_internal.rb, line 140
def map_project_files(dir = :working, year=Date.today.year)
  return unless check_dir(dir)
  if dir == :working
    return map_project_files_working()
  elsif dir == :archive
    return map_project_files_archive year
  else
    @logger.error "unknown path #{dir}"
  end
end
map_project_files_archive(year = Date.today.year) click to toggle source

maps project names to files from working dir

# File lib/luigi_internal.rb, line 127
def map_project_files_archive(year = Date.today.year)
  map={}
  paths = Dir.glob File.join @dirs[:archive], year.to_s, "/*"
  names = paths.map {|path|
    file_path = get_project_file_path (File.basename path), :archive, year
    name = File.basename file_path, @file_extension
    map[name] = file_path
  }
  return map
end
map_project_files_working() click to toggle source

maps project names to files from working dir

# File lib/luigi_internal.rb, line 116
def map_project_files_working()
  map = {}
  folders = Dir.glob File.join @dirs[:working], "/*"
  paths = folders.map {|path| get_project_file_path File.basename path }
  paths.select!{|path| path} # removing faulty paths
  paths.each   {|path| map[File.basename path, @file_extension] = path }
  return map
end
open_project_from_path(path) click to toggle source

opens a project from path

# File lib/luigi_internal.rb, line 103
def open_project_from_path path
  project = @project_class.new({
    :path          => path,
    :settings      => @settings})
  return project if project.class == @project_class
  return false
end