Sha256: d0820489e06ffdf6d838b1721b5f3ea070c7c65ceca4a8f5a4eeb957d50fd567

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

require 'rake/tasklib'

class FlayTask < Rake::TaskLib
  ##
  # The name of the task. Defaults to :flay

  attr_accessor :name

  ##
  # What directories to operate on. Sensible defaults.

  attr_accessor :dirs

  ##
  # Threshold to fail the task at. Default 200.

  attr_accessor :threshold

  ##
  # Verbosity of output. Defaults to rake's trace (-t) option.

  attr_accessor :verbose

  ##
  # Creates a new FlayTask instance with given +name+, +threshold+,
  # and +dirs+.

  def initialize name = :flay, threshold = 200, dirs = nil
    @name      = name
    @dirs      = dirs || %w(app bin lib spec test)
    @threshold = threshold
    @verbose   = Rake.application.options.trace

    yield self if block_given?

    @dirs.reject! { |f| ! File.directory? f }

    define
  end

  ##
  # Defines the flay task.

  def define
    desc "Analyze for code duplication in: #{dirs.join(", ")}"
    task name do
      require "flay"
      flay = Flay.run
      flay.report if verbose

      raise "Flay total too high! #{flay.total} > #{threshold}" if
        flay.total > threshold
    end
    self
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flay-2.13.1 lib/flay_task.rb
flay-2.13.0 lib/flay_task.rb
flay-2.12.1 lib/flay_task.rb
flay-2.12.0 lib/flay_task.rb
flay-2.11.0 lib/flay_task.rb
flay-2.10.0 lib/flay_task.rb
flay-2.9.0 lib/flay_task.rb
flay-2.8.1 lib/flay_task.rb