Sha256: e62eb623e91798795f5757e8e8cb083aab359ee874104127f1910d3715800b46

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

require 'reek/adapters/source'
require 'reek/sniffer'

class Object
  #
  # Creates a new +Sniffer+ that assumes this object contains Ruby source
  # code and examines that code for smells. Calls +to_reek_source+ on self
  # to obtain the +Source+ object wrapper.
  #
  def sniff
    Reek::Sniffer.new(self.to_reek_source)
  end
end

class File
  #
  # Creates a new +Source+ that assumes this File contains Ruby source
  # code and prepares it to be examined for code smells.
  #
  def to_reek_source
    Reek::SourceFile.new(self)
  end
end

class IO
  #
  # Creates a new +Source+ that assumes this IO stream contains Ruby source
  # code and prepares it to be examined for code smells.
  #
  def to_reek_source(description = 'io')
    Reek::Source.new(self.readlines.join, description)
  end
end

class String
  #
  # Creates a new +Source+ that assumes this string contains Ruby source
  # code and prepares it to be examined for code smells.
  #
  def to_reek_source
    Reek::Source.new(self, 'string')
  end
end

class Array
  def paths
    self.map do |path|
      if test 'd', path
        Dir["#{path}/**/*.rb"].paths
      else
        path
      end
    end.flatten.sort
  end

  #
  # Creates a new +Sniffer+ that assumes this Array contains the names
  # of Ruby source files and examines those files for smells.
  #
  def sniff
    sniffers = paths.map {|path| File.new(path).sniff}
    Reek::SnifferSet.new(sniffers, 'dir')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-1.2.6 lib/reek/adapters/core_extras.rb
reek-1.2.5 lib/reek/adapters/core_extras.rb
reek-1.2.4 lib/reek/adapters/core_extras.rb
reek-1.2.3 lib/reek/adapters/core_extras.rb
reek-1.2.2 lib/reek/adapters/core_extras.rb