Parent

Class/Module Index [+]

Quicksearch

Reek::Source::ConfigFile

A file called <something>.reek containing configuration settings for any or all of the smell detectors.

Public Class Methods

new(file_path) click to toggle source

Load the YAML config file from the supplied file_path.

# File lib/reek/source/config_file.rb, line 16
def initialize(file_path)
  @file_path = file_path
  @hash = load
end

Public Instance Methods

configure(sniffer) click to toggle source

Configure the given sniffer using the contents of the config file.

# File lib/reek/source/config_file.rb, line 24
def configure(sniffer)
  @hash.each do |klass_name, config|
    klass = find_class(klass_name)
    sniffer.configure(klass, config) if klass
  end
end
find_class(name) click to toggle source

Find the class with this name if it exsits. If not, report the problem and return nil.

# File lib/reek/source/config_file.rb, line 35
def find_class(name)
  begin
    klass = Reek::Smells.const_get(name)
  rescue
    klass = nil
  end
  problem("\"#{name}\" is not a code smell") unless klass
  klass
end
load() click to toggle source

Load the file path with which this was initialized, unless it is already known to be a bad configuration file. If it won’t load, then it is considered a bad file.

# File lib/reek/source/config_file.rb, line 50
def load
  unless @@bad_config_files.include?(@file_path)
    begin
      return YAML.load_file(@file_path) || {}
    rescue Exception => err
      @@bad_config_files << @file_path
      problem(err.to_s)
    end
  end
  return {}
end
problem(reason) click to toggle source

Report invalid configuration file to standard Error.

# File lib/reek/source/config_file.rb, line 66
def problem(reason)
  $stderr.puts "Error: Invalid configuration file \"#{File.basename(@file_path)}\" -- #{reason}"
  # SMELL: Duplication of 'Error:'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.