Sha256: 4f805e67a02cf939777f6e4d5c365984cfd1d0560d7529d58eb5bef17c2f2bf8

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

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 self.lines(file)
      IO.readlines(file.path)
    end

    def initialize(file)
      @file = file
      super(SourceFile.lines(@file).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

9 entries across 9 versions & 2 rubygems

Version Path
kevinrutherford-reek-1.1.3.12 lib/reek/adapters/source.rb
kevinrutherford-reek-1.1.3.13 lib/reek/adapters/source.rb
kevinrutherford-reek-1.1.3.14 lib/reek/adapters/source.rb
kevinrutherford-reek-1.1.3.15 lib/reek/adapters/source.rb
kevinrutherford-reek-1.1.3.16 lib/reek/adapters/source.rb
kevinrutherford-reek-1.2.0 lib/reek/adapters/source.rb
reek-1.2.2 lib/reek/adapters/source.rb
reek-1.2.1 lib/reek/adapters/source.rb
reek-1.2.0 lib/reek/adapters/source.rb