Skip to content
Browse files

Made it easier to run for the whole project as a rake task

Solving issue #26
  • Loading branch information...
1 parent 1689f2b commit be18af50392357f171ac0bdfd08b9c1e1d8b09b6 @evjan evjan committed Nov 9, 2013
Showing with 12 additions and 16 deletions.
  1. +2 −10 Rakefile
  2. +1 −1 lib/roodi/core/runner.rb
  3. +9 −5 lib/roodi_task.rb
View
12 Rakefile
@@ -3,20 +3,12 @@ require 'rspec/core/rake_task'
require 'bundler'
require 'roodi'
require 'bundler/gem_tasks'
+require 'roodi_task'
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec)
desc "Run Roodi against all source files"
-task :roodi do
- runner = Roodi::Core::Runner.new
- puts "\nRunning Roodi checks"
-
- runner.start([])
- runner.errors.each {|error| puts error}
-
- puts "\nChecked #{runner.files_checked} files"
- puts "Found #{runner.errors.size} errors"
-end
+RoodiTask.new
task :default => [:spec, :roodi]
View
2 lib/roodi/core/runner.rb
@@ -35,7 +35,7 @@ def collect_files(paths)
elsif File.directory?(path)
files += Dir.glob(File.join(path, '**/*.{rb,erb}'))
else
- raise ArgumentError.new("#{path} is neither a File nor a directory!")
+ files += Dir.glob(path)
end
end
files
View
14 lib/roodi_task.rb
@@ -1,3 +1,5 @@
+require 'rake/tasklib'
+
class RoodiTask < Rake::TaskLib
attr_accessor :name
attr_accessor :patterns
@@ -6,7 +8,7 @@ class RoodiTask < Rake::TaskLib
def initialize name = :roodi, patterns = nil, config = nil
@name = name
- @patterns = patterns || %w(app/**/*.rb lib/**/*.rb spec/**/*.rb test/**/*.rb)
+ @patterns = patterns || []
@config = config
@verbose = Rake.application.options.trace
@@ -16,18 +18,20 @@ def initialize name = :roodi, patterns = nil, config = nil
end
def define
- desc "Check for design issues in: #{patterns.join(', ')}"
+ desc "Run Roodi against all source files"
task name do
+ puts "\nRunning Roodi checks"
+
runner = Roodi::Core::Runner.new
runner.config = config if config
- patterns.each do |pattern|
- Dir.glob(pattern).each { |file| runner.check_file(file) }
- end
+ runner.start(@patterns)
runner.errors.each {|error| puts error}
+ puts "\nChecked #{runner.files_checked} files"
+
raise "Found #{runner.errors.size} errors." unless runner.errors.empty?
end
self

0 comments on commit be18af5

Please sign in to comment.
Something went wrong with that request. Please try again.