lib/technologist/framework_detector.rb in technologist-0.5.0 vs lib/technologist/framework_detector.rb in technologist-0.6.0

- old
+ new

@@ -9,36 +9,41 @@ def initialize(repository) @repository = repository @yaml_parser = YamlParser.new(FRAMEWORK_RULES) end + def frameworks + matched_frameworks.flat_map do |technology, definition| + [definition['primary'], technology] + end.compact.uniq + end + def primary_frameworks - matched_frameworks.map do |technology| + matched_frameworks.map do |technology, definition| # it's either the primary value defined in the yaml # or the technology itself - yaml_parser.rules[technology]['primary'] || technology + definition['primary'] || technology end.uniq end def secondary_frameworks - matched_frameworks.map do |technology| + matched_frameworks.map do |technology, definition| # it's a secondary if a primary is defined in the yaml - yaml_parser.rules[technology]['primary'] && technology + definition['primary'] && technology end.compact end private def matched_frameworks @frameworks ||= begin - yaml_parser.rules.map do |technology, definition| - definition['rules'].map do |rule| - if rule.matches?(repository) - technology - end + matched_rules = yaml_parser.rules.select do |technology, definition| + definition['rules'].any? do |rule| + rule.matches?(repository) end - end.flatten.compact + end + Hash[matched_rules] end end end end