Sha256: db4cd6e3035a36d131ce8fc6acc6a2e944caf329b40bfd2bdaf886d945b292b4
Contents?: true
Size: 1.6 KB
Versions: 9
Compression:
Stored size: 1.6 KB
Contents
# Using `reek` inside your Ruby application `reek` can be used inside another Ruby project. ```bash gem install reek ``` ## Using a reporter You can use reek inside your Ruby file `check_dirty.rb` ```ruby require 'reek' source = <<-END class Dirty # This method smells of :reek:NestedIterators but ignores them def awful(x, y, offset = 0, log = false) puts @screen.title @screen = widgets.map { |w| w.each { |key| key += 3 * x } } puts @screen.contents fail end end END reporter = Reek::Report::TextReport.new examiner = Reek::Examiner.new(source) reporter.add_examiner examiner reporter.show ``` This will show the list of errors in variable `source`. `Reek::Examiner.new` can take `source` as `String`, `File` or `IO`. ``` # Examine a file object reporter.add_examiner Reek::Examiner.new(File.new('dirty.rb')) ``` Also, besides normal text output, `reek` can generate output in YAML, JSON, HTML and XML by using the following Report types: ``` TextReport YAMLReport JSONReport HTMLReport XMLReport ``` ## Accessing the smell warnings directly You can also access the smells detected by an examiner directly: ```ruby require 'reek' source = <<-END class Dirty # This method smells of :reek:NestedIterators but ignores them def awful(x, y, offset = 0, log = false) puts @screen.title @screen = widgets.map { |w| w.each { |key| key += 3 * x } } puts @screen.contents fail end end END examiner = Reek::Examiner.new(source) examiner.smells.each do |smell| puts smell.message end ``` `Examiner#smells` returns a list of `SmellWarning` objects.
Version data entries
9 entries across 9 versions & 1 rubygems