Sha256: 0f1c145b13ef721db5b0b524b8427f979b97da73309ebef84a77cd2aeacc03e1

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module MetricFu
  class RailsBestPracticesGenerator < Generator
    def self.metric
      :rails_best_practices
    end

    def initialize(options = {})
      super(MetricFu::Utility.stringify_keys(options))
    end

    def emit
      mf_debug "** Rails Best Practices"
      path = "."
      analyzer = ::RailsBestPractices::Analyzer.new(path, options)
      analyzer.analyze
      @output = analyzer.errors
    end

    def analyze
      @problems = @output.collect do |problem|
        {
          file: problem.filename,
          line: problem.line_number,
          problem: problem.message,
          url: problem.url
        }
      end
      total = ["Found #{@problems.count} errors."]
      @rails_best_practices_results = { total: total, problems: @problems }
    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?

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
metric_fu-4.13.0 lib/metric_fu/metrics/rails_best_practices/generator.rb
fastruby-metric_fu-5.0.0 lib/metric_fu/metrics/rails_best_practices/generator.rb