Fix ruby filter
@@ -69,55 +69,42 @@ def python(files, input_files, **kwargs):
def ruby(files, input_files, **kwargs):
- extensions = list(map(lambda ext: ext.encode('utf-8'),
- ['.rb',
- '.haml',
- '.slim',
- '.erb',
- '.js',
- '.html']))
- ignored_dirs = list(map(lambda ext: ext.encode('utf-8'),
- ['spec',
- 'test',
- 'tests',
- 'guides',
- 'doc-api',
- 'rdoc',
- 'doc']))
-
- gemy_path = re.compile(r'.*\/ruby[-/]\d+\.\d+\.\d+\/gems')
- appdir_paths = re.compile(r'.*\/app\/(views|'
- 'controllers|models|'
- 'helpers)$')
-
- seen_paths = []
- add = []
+ extensions = set(ext.encode('utf-8') for ext in [
+ '.rb', '.haml', '.slim', '.erb', '.js', '.html',
+ ])
+ ignored_dirs = set(name.encode('utf-8') for name in [
+ 'spec', 'test', 'tests', 'guides', 'doc-api', 'rdoc', 'doc',
+ ])
- def consume(dir_or_file):
- dir_or_file = Path(dir_or_file)
- if (dir_or_file.is_file() and
- dir_or_file.ext in extensions and
- dir_or_file not in files):
- logger.info("Adding %s", dir_or_file)
- add.append(TracedFile(dir_or_file))
- elif (dir_or_file.is_dir() and
- dir_or_file.name not in ignored_dirs):
- for child in dir_or_file.listdir():
- consume(child)
+ gemy_path = re.compile(r'^.*/ruby[-/]\d+\.\d+\.\d+/gems')
+ appdir_paths = re.compile(r'^.*/app/(views|controllers|models|helpers)')
+
+ directories = set()
for path, fi in iteritems(files):
m1 = gemy_path.match(str(path))
- if m1 and m1.group(0) not in seen_paths:
- consume(m1.group(0))
- seen_paths.append(m1.group(0))
- elif m1:
- continue
+ if m1:
+ directories.add(Path(m1.group(0)))
m2 = appdir_paths.match(str(path))
- if (m2 and m2.group(0) not in seen_paths and
- (path.parent.parent / 'config/application.rb').is_file()):
- consume(m2.group(0))
- seen_paths.append(m2.group(0))
+ if m2:
+ app_root = Path(m2.group(0)).parent.parent
+ if (app_root / 'config/application.rb').is_file():
+ directories.add(app_root)
- for fi in add:
- files[fi.path] = fi
+ def add_recursive(dir_or_file):
+ if (
+ dir_or_file.is_file()
+ and dir_or_file.ext in extensions
+ ):
+ logger.info("Adding %s", dir_or_file)
+ files[dir_or_file] = TracedFile(dir_or_file)
+ elif (
+ dir_or_file.is_dir()
+ and dir_or_file.name not in ignored_dirs
+ ):
+ for child in dir_or_file.listdir():
+ add_recursive(child)
+
+ for directory in directories:
+ add_recursive(directory)
