Sha256: 34d93db56a59ec72e0fd1cdbadffd0e63b4422159286aa74111032348283f571

Contents?: true

Size: 1.84 KB

Versions: 10

Compression:

Stored size: 1.84 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_dependencies
    @shell_output = begin
      `reek app/models lib -y 2>/dev/null`
    rescue Errno::ENOENT
      "Reek not found"
    end
    @shell_output = @shell_output.split("\n").delete_if do |line|
      line.include?('already initialized constant')
    end.join("\n")
    { type: :reek, check_output: output, status: status }
  end

  private
    ##
    # Require Dependencies
    #
    # @author dmasur
    def require_dependencies
      require 'reek'
      require 'colored'
      require 'yaml'
    end
    ##
    # 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
      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

10 entries across 10 versions & 1 rubygems

Version Path
rake_check-0.3.5 lib/rake_check/reek_checker.rb
rake_check-0.3.4 lib/rake_check/reek_checker.rb
rake_check-0.3.3 lib/rake_check/reek_checker.rb
rake_check-0.3.2 lib/rake_check/reek_checker.rb
rake_check-0.3.1 lib/rake_check/reek_checker.rb
rake_check-0.3.0 lib/rake_check/reek_checker.rb
rake_check-0.2.2 lib/rake_check/reek_checker.rb
rake_check-0.2.1 lib/rake_check/reek_checker.rb
rake_check-0.2 lib/rake_check/reek_checker.rb
rake_check-0.1.11 lib/rake_check/reek_checker.rb