Sha256: 034217c6e7ff6010d74a6553540bcc4c5ee43b3349df2aa2092ac4934e9b22ec

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

require 'reek/smells/control_couple'
require 'reek/smells/duplication'
require 'reek/smells/feature_envy'
require 'reek/smells/large_class'
require 'reek/smells/long_method'
require 'reek/smells/long_parameter_list'
require 'reek/smells/long_yield_list'
require 'reek/smells/nested_iterators'
require 'reek/smells/uncommunicative_name'
require 'reek/smells/utility_function'
require 'yaml'

class Hash
  def push_keys(hash)
    keys.each {|key| hash[key].adopt!(self[key]) }
  end

  def adopt!(other)
    other.keys.each do |key|
      ov = other[key]
      if Array === ov and has_key?(key)
        self[key] += ov
      else
        self[key] = ov
      end
    end
    self
  end
  
  def adopt(other)
    self.deep_copy.adopt!(other)
  end
  
  def deep_copy
    YAML::load(YAML::dump(self))
  end
end

module Reek
  class SmellConfig

    SMELL_CLASSES = [
      Smells::ControlCouple,
      Smells::Duplication,
      Smells::FeatureEnvy,
      Smells::LargeClass,
      Smells::LongMethod,
      Smells::LongParameterList,
      Smells::LongYieldList,
      Smells::NestedIterators,
      Smells::UncommunicativeName,
      Smells::UtilityFunction,
    ]

    def initialize
      defaults_file = File.join(File.dirname(__FILE__), '..', '..', '..', 'config', 'defaults.reek')
      @config = YAML.load_file(defaults_file)
    end

    def smell_listeners()
      result = Hash.new {|hash,key| hash[key] = [] }
      SMELL_CLASSES.each { |smell| smell.listen(result, @config) }
      return result
    end

    def load_local(file)
      path = File.expand_path(file)
      all_reekfiles(path).each do |rfile|
        YAML.load_file(rfile).push_keys(@config)
      end
      self
    end

    def all_reekfiles(path)
      return [] unless File.exist?(path)
      parent = File.dirname(path)
      return [] if path == parent
      all_reekfiles(parent) + Dir["#{path}/*.reek"]
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
kevinrutherford-reek-1.1.1 lib/reek/smells/smells.rb
kevinrutherford-reek-1.1.2.1 lib/reek/smells/smells.rb
kevinrutherford-reek-1.1.2 lib/reek/smells/smells.rb
kevinrutherford-reek-1.1.3.1 lib/reek/smells/smells.rb
kevinrutherford-reek-1.1.3 lib/reek/smells/smells.rb
teksymmetry-reek-1.1.3.1 lib/reek/smells/smells.rb
teksymmetry-reek-1.1.3.2 lib/reek/smells/smells.rb
reek-1.1.3 lib/reek/smells/smells.rb