janitor 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+
23
+ tmp/
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Tim Harvey and Michael Krisher
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.mdown ADDED
@@ -0,0 +1,33 @@
1
+ Janitor Gem
2
+ =============
3
+
4
+ Tim Harvey
5
+
6
+ Mike Krisher
7
+
8
+
9
+ Details
10
+ =======
11
+
12
+ Need a code janitor? Someone to scan your code base and look
13
+ for leftover debug statements, console logs, and gasp, vulgarity!
14
+
15
+ Simple to use, point it at your code base, and run janitor report
16
+
17
+ To learn more about Ack:
18
+ [http://betterthangrep.com][]
19
+
20
+ [http://betterthangrep.com/]: http://betterthangrep.com
21
+
22
+ Installation
23
+ ============
24
+
25
+ Install the gem.
26
+
27
+ gem install janitor
28
+
29
+ Configure your app to load the Janitor rake tasks by adding the following to you Rakefile:
30
+
31
+ # Code cleanup goodies
32
+ require 'janitor/tasks'
33
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ $:.unshift 'lib'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "janitor"
10
+ gem.summary = "janitor scans your code for leftover debug statements, consolr logs, and vulgarity"
11
+ gem.description = "ever leave a breakpoint in your code and do a deploy? not good, right? maybe you just want to remove the logger.info calls from your Rails project. janitor cleans your code"
12
+ gem.email = "mike@mikekrisher.com"
13
+ gem.homepage = "http://github.com/tjh/janitor"
14
+ gem.authors = ["Tim Harvey", "Michael Krisher"]
15
+ gem.add_dependency "rak"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+ task :test => :check_dependencies
50
+
51
+ task :default => :test
52
+
53
+ begin
54
+ require 'yard'
55
+ YARD::Rake::YardocTask.new
56
+ rescue LoadError
57
+ task :yardoc do
58
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
59
+ end
60
+ end
61
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/janitor.gemspec ADDED
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{janitor}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tim Harvey", "Michael Krisher"]
12
+ s.date = %q{2010-09-04}
13
+ s.description = %q{ever leave a breakpoint in your code and do a deploy? not good, right? maybe you just want to remove the logger.info calls from your Rails project. janitor cleans your code}
14
+ s.email = %q{mike@mikekrisher.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.mdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.mdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "init.rb",
27
+ "janitor.gemspec",
28
+ "lib/finder.rb",
29
+ "lib/janitor.rb",
30
+ "lib/janitor/finder.rb",
31
+ "lib/janitor/janitor.rb",
32
+ "lib/janitor/rak_result.rb",
33
+ "lib/janitor/tasks.rb",
34
+ "lib/tasks/tasks.rake",
35
+ "nails/init.rb",
36
+ "spec/lib/finder_spec.rb",
37
+ "spec/lib/janitor_spec.rb",
38
+ "spec/lib/rak_result_spec.rb",
39
+ "spec/spec.opts",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/tjh/janitor}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.7}
46
+ s.summary = %q{janitor scans your code for leftover debug statements, consolr logs, and vulgarity}
47
+ s.test_files = [
48
+ "spec/lib/finder_spec.rb",
49
+ "spec/lib/janitor_spec.rb",
50
+ "spec/lib/rak_result_spec.rb",
51
+ "spec/spec_helper.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<rak>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<rak>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<rak>, [">= 0"])
65
+ end
66
+ end
67
+
data/lib/finder.rb ADDED
@@ -0,0 +1,20 @@
1
+ class Finder
2
+ attr_reader :path
3
+
4
+ def initialize(path = File.dirname(__FILE__))
5
+ @path = path
6
+ end
7
+
8
+ def number_of_matches(pattern)
9
+ rak_result = search_by_regex(pattern)
10
+ rak_result.files.size
11
+ end
12
+
13
+ def search_by_regex(pattern)
14
+ exec_rak(pattern, '-all')
15
+ end
16
+
17
+ def exec_rak(pattern, options)
18
+ RakResult.new(%x{rak #{options} #{pattern} #{@path}})
19
+ end
20
+ end
data/lib/janitor.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'janitor/janitor'
2
+ require 'janitor/finder'
3
+ require 'janitor/tasks'
4
+ require 'janitor/rak_result'
@@ -0,0 +1,20 @@
1
+ class Finder
2
+ attr_reader :path
3
+
4
+ def initialize(path = File.dirname(__FILE__))
5
+ @path = path
6
+ end
7
+
8
+ def number_of_matches(pattern)
9
+ rak_result = search_by_regex(pattern)
10
+ rak_result.files.size
11
+ end
12
+
13
+ def search_by_regex(pattern)
14
+ exec_rak(pattern, '-all')
15
+ end
16
+
17
+ def exec_rak(pattern, options)
18
+ RakResult.new(%x{rak #{options} #{pattern} #{@path}})
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ class Janitor
2
+ def self.count (pattern, path = "*")
3
+ finder = Finder.new(path)
4
+ count = finder.number_of_matches(pattern)
5
+ raise "Found #{pattern} #{count} times in #{path}" if count > 0
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class RakResult
2
+ attr_accessor :rak_output
3
+
4
+ def initialize(rak_output)
5
+ self.rak_output = rak_output
6
+ end
7
+
8
+ def files
9
+ rows = rak_output.split("\n")
10
+ rows.select { |r| r.scan(/^[^\s]+/).size > 0 }
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'janitor'
2
+
3
+ namespace :janitor do
4
+ namespace :count do
5
+ desc "Run all count tasks"
6
+ task :all => [:debugger, :console_log]
7
+
8
+ desc "Find any 'console.log' statements"
9
+ task :console_log do
10
+ count = Janitor.count "console.log", "tmp/javascript"
11
+ raise "Found console.log statements" if count > 0
12
+ end
13
+
14
+ desc "Count 'debugger' statements"
15
+ task :debugger do
16
+ count = Janitor.count "debugger"
17
+ raise "Found debugger statements" if count > 0
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'janitor', 'tasks'))
data/nails/init.rb ADDED
File without changes
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Finder" do
4
+ describe " #initialize" do
5
+ it "should store the given path" do
6
+ finder = Finder.new('a_path')
7
+ finder.path.should == 'a_path'
8
+ end
9
+ end
10
+
11
+ describe " #search_by_regex" do
12
+ it "should execute a rak search with the given pattern and -all" do
13
+ pattern = 'a_regex'
14
+ finder = Finder.new
15
+ finder.should_receive(:exec_rak).with(pattern, '-all')
16
+ finder.search_by_regex(pattern)
17
+ end
18
+ end
19
+
20
+ describe " #exec_rak" do
21
+ it "should return a RakResult instance" do
22
+ pattern = 'a_regex'
23
+ finder = Finder.new
24
+ finder.exec_rak('search', 'option').should be_instance_of(RakResult)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Janitor" do
4
+ describe " #count" do
5
+ it "should call number_of_matches on Finder with the given path" do
6
+ path = "a_path"
7
+ pattern = "a_pattern"
8
+ finder = mock('finder')
9
+ finder.should_receive(:number_of_matches).with(pattern).and_return(0)
10
+ Finder.should_receive(:new).with(path).and_return(finder)
11
+ Janitor.count(path, pattern)
12
+ end
13
+
14
+ it "should raise an exception when number_of_matches returns a non-zero count" do
15
+ path = "a_path"
16
+ pattern = "a_pattern"
17
+ finder = mock('finder')
18
+ finder.should_receive(:number_of_matches).with(pattern).and_return(1)
19
+ Finder.should_receive(:new).with(path).and_return(finder)
20
+ lambda { Janitor.count(path, pattern) }.should raise_error
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "RakResult" do
4
+ before(:all) do
5
+ @result = "
6
+ lib/janitor.rb
7
+ 1|require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
8
+ 9|end
9
+
10
+ lib/finder.rb
11
+ 7|Dir.glob(File.join(File.dirname(__FILE__), '../lib/*.rb')).each {|f| require f }
12
+ 9|Spec::Runner.configure do |config|
13
+ 11|end
14
+ "
15
+ end
16
+
17
+ describe " #initialize" do
18
+ it "should store the given rak output string" do
19
+ RakResult.new('a_result').rak_output.should == 'a_result'
20
+ end
21
+ end
22
+
23
+ describe " #file_matches" do
24
+ it "should return an array of files that were matched" do
25
+ RakResult.new(@result).files.should == ['lib/janitor.rb', 'lib/finder.rb']
26
+ end
27
+ end
28
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ # Require each of our libraries
7
+ Dir.glob(File.join(File.dirname(__FILE__), '../lib/**/*.rb')).each {|f| require f }
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: janitor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Tim Harvey
14
+ - Michael Krisher
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-09-04 00:00:00 -05:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rak
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: ever leave a breakpoint in your code and do a deploy? not good, right? maybe you just want to remove the logger.info calls from your Rails project. janitor cleans your code
37
+ email: mike@mikekrisher.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.mdown
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.mdown
50
+ - Rakefile
51
+ - VERSION
52
+ - init.rb
53
+ - janitor.gemspec
54
+ - lib/finder.rb
55
+ - lib/janitor.rb
56
+ - lib/janitor/finder.rb
57
+ - lib/janitor/janitor.rb
58
+ - lib/janitor/rak_result.rb
59
+ - lib/janitor/tasks.rb
60
+ - lib/tasks/tasks.rake
61
+ - nails/init.rb
62
+ - spec/lib/finder_spec.rb
63
+ - spec/lib/janitor_spec.rb
64
+ - spec/lib/rak_result_spec.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/tjh/janitor
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: janitor scans your code for leftover debug statements, consolr logs, and vulgarity
101
+ test_files:
102
+ - spec/lib/finder_spec.rb
103
+ - spec/lib/janitor_spec.rb
104
+ - spec/lib/rak_result_spec.rb
105
+ - spec/spec_helper.rb