lib/card/loader.rb in card-1.16.1 vs lib/card/loader.rb in card-1.16.2

- old
+ new

@@ -19,11 +19,11 @@ class << self def load_mods load_set_patterns load_formats load_sets - + if Wagn.config.performance_logger Card::Log::Performance.load_config Wagn.config.performance_logger end end @@ -46,15 +46,10 @@ end end def mod_dirs @@mod_dirs ||= begin - if Card.paths['local-mod'] - Card.paths['mod'] << Card.paths['local-mod'] - Rails.logger.warn 'DEPRECATION WARNING: Append to paths[\'mod\'] vs. local-mod for configuring location of local (deck) modules.' - end - Card.paths['mod'].existent.map do |dirname| Dir.entries( dirname ).sort.map do |filename| "#{dirname}/#{filename}" if filename !~ /^\./ end.compact end.flatten.compact @@ -63,16 +58,16 @@ private def load_set_patterns if rewrite_tmp_files? - load_set_patterns_from_source + generate_set_pattern_tmp_files end load_dir "#{Card.paths['tmp/set_pattern'].first}/*.rb" end - def load_set_patterns_from_source + def generate_set_pattern_tmp_files prepare_tmp_dir 'tmp/set_pattern' seq = 100 mod_dirs.each do |mod| dirname = "#{mod}/set_pattern" if Dir.exists? dirname @@ -93,46 +88,51 @@ load_dir "#{mod}/format/*.rb" end end def load_sets - prepare_tmp_dir 'tmp/set' - load_sets_by_pattern + generate_tmp_set_modules + load_tmp_set_modules Set.process_base_modules Set.clean_empty_modules end - def load_sets_by_pattern - Card.set_patterns.reverse.map(&:pattern_code).each do |set_pattern| - pattern_tmp_dir = "#{Card.paths['tmp/set'].first}/#{set_pattern}" - if rewrite_tmp_files? - Dir.mkdir pattern_tmp_dir - load_implicit_sets_from_source set_pattern + def generate_tmp_set_modules + if prepare_tmp_dir 'tmp/set' + seq = 1 + mod_dirs.each do |mod_dir| + mod_tmp_dir = make_set_module_tmp_dir mod_dir, seq + Dir.glob("#{mod_dir}/set/**/*.rb").each do |abs_filename| + rel_filename = abs_filename.gsub "#{mod_dir}/set/", '' + tmp_filename = "#{mod_tmp_dir}/#{rel_filename}" + Set.write_tmp_file abs_filename, tmp_filename, rel_filename + end + seq = seq + 1 end - if Dir.exists? pattern_tmp_dir - load_dir "#{pattern_tmp_dir}/**/*.rb" - end end end - def load_implicit_sets_from_source set_pattern - seq = 1000 - mod_dirs.each do |mod_dir| - dirname = [mod_dir, 'set', set_pattern] * '/' - next unless File.exists?( dirname ) - old_pwd = Dir.pwd - Dir.chdir dirname - Dir.glob( "**/*.rb" ).sort.each do |anchor_path| - path_parts = anchor_path.gsub(/\.rb/,'').split(File::SEPARATOR) - filename = File.join dirname, anchor_path - Set.write_tmp_file set_pattern, path_parts, filename, seq - seq = seq + 1 + def load_tmp_set_modules + patterns = Card.set_patterns.reverse.map(&:pattern_code).unshift 'abstract' + Dir.glob( "#{Card.paths['tmp/set'].first}/*" ).sort.each do |tmp_mod| + patterns.each do |pattern| + pattern_dir = "#{tmp_mod}/#{pattern}" + if Dir.exists? pattern_dir + load_dir "#{pattern_dir}/**/*.rb" + end end - Dir.chdir old_pwd end end + + def make_set_module_tmp_dir mod_dir, seq + modname = mod_dir.match(/[^\/]+$/)[0] + mod_tmp_dir = "#{Card.paths['tmp/set'].first}/mod#{"%03d" % seq}-#{modname}" + Dir.mkdir mod_tmp_dir + mod_tmp_dir + end + def prepare_tmp_dir path if rewrite_tmp_files? p = Card.paths[ path ] if p.existent.first