Sha256: 81bd8ae9226481622f28a71338b85d2624d83d1a9b9642f5b49d0641f249b42b

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

##
# ReekChecker checks the Output of reek for Code Smells
#
# @author dmasur
class ReekChecker
  ##
  # Gives the Checkresult
  #
  # @return [Hash] Checkresult
  # @author dmasur
  def result
    require 'reek'
    require 'colored'
    require 'yaml'
    shell_output = `reek app lib -y 2>/dev/null`
    @shell_output = shell_output.split("\n").
      delete_if{|line| line.include?('already initialized constant') }.join("\n")
    {:type => :reek, :check_output => output, :status => status}
  end

  private
    ##
    # Gives the Check Status
    #
    # @return [String] Checkstatus
    # @author dmasur
    def status
      if @shell_output.empty?
        'OK'.green
      elsif not @shell_output.include? '---'
        'N/A'.red
      else
        error_count = parsed_output.count
        "#{error_count} Codesmell".yellow
      end
    end

    ##
    # Parse the Output through YAML
    #
    # @return [Array] SmellWarnings
    # @author dmasur
    def parsed_output
      puts @shell_output
      YAML::load(@shell_output)
    end

    ##
    # Format the SmellWarning for printing
    #
    # @return [String] Formated SmellWarning
    # @author dmasur
    def self.format_smell smell_warning
      location = smell_warning.location
      output = "#{smell_warning.smell["subclass"]}: "
      output += "#{location["context"]}@#{location["lines"].join(", ")}"
      return output
    end

    ##
    # Gives the check output
    #
    # @return [String] Output
    # @author dmasur
    def output
      if @shell_output.include? '---'
        parsed_output.map do |smell|
          ReekChecker.format_smell smell
        end.join("\n")
      else
        @shell_output
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake_check-0.1.1 lib/rake_check/reek_checker.rb