Sha256: 071d4c4217005965356a60b6bdfa94c9254dae10ee89e20e4d95dccc06b0a9a1

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module MetricFu
  class RailsBestPractices < Generator
    VERSION = '0.10.1'
    def emit
      @output = `rails_best_practices _#{VERSION}_ --without-color .`
    end

    def analyze
      @matches = @output.chomp.split("\n").map{|m| m.split(" - ") }
      total = @matches.pop
      cleanup_color_switches(total.first)

      2.times { @matches.pop } # ignore wiki link
      @matches.reject! {|array| array.empty? }
      @matches.map! do |match|
        file, line = match[0].split(':')
        problem = match[1]

        cleanup_color_switches(file)
        cleanup_color_switches(problem)

        file.gsub!(/^\.\//, '')

        {:file => file, :line => line, :problem => problem}
      end
      @rails_best_practices_results = {:total => total, :problems => @matches}
    end

    def cleanup_color_switches(str)
      return if str.nil?
      str.gsub!(%r{^\e\[3[1|2]m}, '')
      str.gsub!(%r{\e\[0m$}, '')
    end

    def to_h
      {:rails_best_practices => @rails_best_practices_results}
    end

    def per_file_info(out)
      @rails_best_practices_results[:problems].each do |problem|
        next if problem[:file] == '' || problem[:problem].nil?

        out[problem[:file]] ||= {}

        lines = problem[:line].split(/\s*,\s*/)
        lines.each do |line|
          out[problem[:file]][line] ||= []
          out[problem[:file]][line] << {:type => :rails_best_practices, :description => problem[:problem]}
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metric_fu-2.1.3.7.18.1 lib/metrics/rails_best_practices/rails_best_practices.rb
metric_fu-2.1.3.7.19 lib/metrics/rails_best_practices/rails_best_practices.rb
metric_fu-2.1.3.6 lib/metrics/rails_best_practices/rails_best_practices.rb