Sha256: bfc7b31584d3a2125c7de933534f370cb3bf8900ac9219d40c735eee23ef4da9

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module MetricFu
  
  class Reek < Generator
    REEK_REGEX = /^(\S+) (.*) \((.*)\)$/

    def self.verify_dependencies!
      `reek --help`
      raise 'sudo gem install reek # if you want the reek tasks' unless $?.success?
    end

    def emit
      files_to_reek = MetricFu.reek[:dirs_to_reek].map{|dir| Dir[File.join(dir, "**/*.rb")] }
      @output = `reek #{files_to_reek.join(" ")}`
    end

    def analyze
      @matches = @output.chomp.split(/^(?=\S)/).map{|m| m.split("\n") }
      @matches = @matches.map do |match|
        file_path = match.shift.split('--').first
        file_path = file_path.gsub('"', ' ').strip
        code_smells = match.map do |smell|
          match_object = smell.strip.match(REEK_REGEX)
          next unless match_object
          {:method => match_object[1].strip,
           :message => match_object[2].strip,
           :type => match_object[3].strip}
        end.compact
        {:file_path => file_path, :code_smells => code_smells}
      end
    end

    def to_h
      {:reek => {:matches => @matches}}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mattvanhorn-metric_fu-1.1.5.2 lib/generators/reek.rb