Sha256: 706b512f7a9c2b13311e7791cb9afb49f9a28c381e911c79ce5c52719cf933da

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require 'technologist/yaml_parser'

module Technologist
  class FrameworkDetector
    FRAMEWORK_RULES = File.expand_path('../frameworks.yml',  __FILE__)

    attr_reader :repository, :yaml_parser

    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, definition|
        # it's either the primary value defined in the yaml
        # or the technology itself
        definition['primary'] || technology
      end.uniq
    end

    def secondary_frameworks
      matched_frameworks.map do |technology, definition|
        # it's a secondary if a primary is defined in the yaml
        definition['primary'] && technology
      end.compact
    end

    private

    def matched_frameworks
      @frameworks ||=
        begin
          matched_rules = yaml_parser.rules.select do |technology, definition|
            definition['rules'].any? do |rule|
              rule.matches?(repository)
            end
          end
          Hash[matched_rules]
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
technologist-0.6.1 lib/technologist/framework_detector.rb
technologist-0.6.0 lib/technologist/framework_detector.rb