Class: LuigiInternal
- Inherits:
-
Object
- Object
- LuigiInternal
- Defined in:
- lib/luigi_internal.rb
Overview
implements everything not exposed to the outside TODO: make this all private
Instance Method Summary collapse
-
#_new_project_folder(name) ⇒ Object
creates new project_dir and project_file.
-
#check_dir(dir) ⇒ Object
Checks the existens of one of the three basic dirs.
-
#check_dirs ⇒ Object
Checks the existens of every thing required.
-
#get_project_file_path(name, dir = :working, year = Date.today.year) ⇒ Object
derives path to project file from name there may only be one @file_extension file per project folder.
- #init_dirs ⇒ Object
- #init_logger ⇒ Object
-
#list_project_files_all ⇒ Object
list projects lists project files.
-
#list_project_files_archive(year = Date.today.year) ⇒ Object
lists project files from archive directory.
-
#list_project_files_working ⇒ Object
lists project files from working directory.
-
#load_templates ⇒ Object
read the templates directory and cache paths.
-
#map_archive_years ⇒ Object
returns map of years to archive folders.
-
#map_project_files(dir = :working, year = Date.today.year) ⇒ Object
maps project names to files.
-
#map_project_files_archive(year = Date.today.year) ⇒ Object
maps project names to files from working dir.
-
#map_project_files_working ⇒ Object
maps project names to files from working dir.
-
#open_project_from_path(path) ⇒ Object
opens a project from path.
Instance Method Details
#_new_project_folder(name) ⇒ Object
creates new project_dir and project_file
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
Checks the existens of one of the three basic dirs. dir can be either :storage, :working or :archive and also :templates
36 37 38 |
# File 'lib/luigi_internal.rb', line 36 def check_dir(dir) File.exists? @dirs[dir] end |
#check_dirs ⇒ Object
Checks the existens of every thing required
42 43 44 45 46 47 |
# 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) ⇒ Object
derives path to project file from name there may only be one @file_extension file per project folder
untested
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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 ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/luigi_internal.rb', line 22 def init_dirs @dirs = {} if @settings.dirs.storage? @dirs[:storage] = File.(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 ⇒ Object
15 16 17 18 19 20 |
# 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 ⇒ Object
list projects lists project files
178 179 180 181 182 183 184 185 |
# 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) ⇒ Object
lists project files from archive directory
171 172 173 |
# 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 ⇒ Object
lists project files from working directory
166 167 168 |
# File 'lib/luigi_internal.rb', line 166 def list_project_files_working() map_project_files_working.values end |
#load_templates ⇒ Object
read the templates directory and cache paths
50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
returns map of years to archive folders
153 154 155 156 157 158 159 |
# 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) ⇒ Object
maps project names to files
140 141 142 143 144 145 146 147 148 149 |
# 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) ⇒ Object
maps project names to files from working dir
127 128 129 130 131 132 133 134 135 136 |
# 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 ⇒ Object
maps project names to files from working dir
116 117 118 119 120 121 122 123 |
# 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) ⇒ Object
opens a project from path
103 104 105 106 107 108 109 |
# 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 |