Sha256: 3ae6505a6af1ade840689e93a847b15a658d913f7e707e1c3f78ccc7751ee540

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

require 'reek/adapters/config_file'

module Reek

  #
  # A +Source+ object represents a chunk of Ruby source code.
  #
  class Source

    attr_reader :desc

    def initialize(code, desc)
      @source = code
      @desc = desc
    end

    def configure(sniffer) end

    def syntax_tree
      RubyParser.new.parse(@source, @desc) || s()
    end
  end

  #
  # Represents a file of Ruby source, whose contents will be examined
  # for code smells.
  #
  class SourceFile < Source

    def initialize(file)
      @file = file
      super(@file.lines.to_a.join, @file.path)
    end

    def configure(sniffer)
      path = File.expand_path(File.dirname(@file.path))
      all_config_files(path).each { |cf| ConfigFile.new(cf).configure(sniffer) }
    end

  private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.11 lib/reek/adapters/source.rb