stowaway 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/README.md +12 -1
- data/VERSION.yml +1 -1
- data/lib/stowaway/runner.rb +3 -1
- data/lib/stowaway/status.rb +14 -0
- data/lib/stowaway/sweeper.rb +18 -13
- data/spec/lib/sweeper_spec.rb +23 -15
- data/stowaway.gemspec +5 -5
- metadata +4 -4
- data/bin/.stowaway.swp +0 -0
- data/pkg/stowaway-0.0.1.gem +0 -0
data/README.md
CHANGED
@@ -12,7 +12,18 @@ Stowaway is a gem that searches a web project for files that aren't being used.
|
|
12
12
|
## Installing
|
13
13
|
|
14
14
|
sudo gem install stowaway
|
15
|
-
|
15
|
+
|
16
|
+
## Usages
|
17
|
+
|
18
|
+
# basic usage
|
19
|
+
stowaway path/to/site
|
20
|
+
|
21
|
+
# from directory
|
22
|
+
stowaway .
|
23
|
+
|
24
|
+
# with file types
|
25
|
+
stowaway -t .js .css path/to/site
|
26
|
+
|
16
27
|
## Note
|
17
28
|
|
18
29
|
I'll be adding support for matching on relative and absolute paths (Comparing by path will preserve the uniqueness of the file). Currently, only file names are being checked for matches. If you have two files with the same name but they reside in different directories, they will be treated as one. In other words, if you have multiple files with the *same name*, stowaway won't work right.
|
data/VERSION.yml
CHANGED
data/lib/stowaway/runner.rb
CHANGED
@@ -10,9 +10,11 @@ module Stowaway
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def run
|
13
|
+
p "Locating files ..."
|
13
14
|
locator = Stowaway::Locator.new(@options.file_types)
|
14
15
|
files = locator.find_all @options.path
|
15
|
-
|
16
|
+
p "#{files.size} files located"
|
17
|
+
|
16
18
|
fs = Stowaway::Sweeper.new files
|
17
19
|
respond fs.sweep @options.path
|
18
20
|
end
|
data/lib/stowaway/sweeper.rb
CHANGED
@@ -1,25 +1,16 @@
|
|
1
1
|
require_relative 'fshelpyhelp'
|
2
|
+
require_relative 'status'
|
2
3
|
|
3
4
|
module Stowaway
|
4
5
|
class Sweeper
|
5
6
|
include FSHelpyHelp
|
6
7
|
|
7
|
-
def initialize(files_to_find, ext_to_ignore = nil)
|
8
|
+
def initialize(files_to_find, status = Status.new, ext_to_ignore = nil)
|
8
9
|
@files_to_find = files_to_find
|
9
10
|
@ignore = ext_to_ignore || [/^\.|\.jpg$|\.gif$|.png$/i]
|
11
|
+
@status = status
|
10
12
|
end
|
11
13
|
|
12
|
-
def inspect_file(file)
|
13
|
-
File.open(file, 'r') do |i|
|
14
|
-
while line = i.gets
|
15
|
-
remove_match(line)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_match(line)
|
21
|
-
@files_to_find.delete_if { |file| line.include?(file.name) }
|
22
|
-
end
|
23
14
|
|
24
15
|
def sweep(path)
|
25
16
|
dir = Dir.new(path)
|
@@ -38,5 +29,19 @@ module Stowaway
|
|
38
29
|
@files_to_find
|
39
30
|
end
|
40
31
|
|
32
|
+
private
|
33
|
+
def inspect_file(file)
|
34
|
+
@status.out "Sweeping: #{file}"
|
35
|
+
File.open(file, 'r') do |i|
|
36
|
+
while line = i.gets
|
37
|
+
remove_match(line)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
@status.flush
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_match(line)
|
44
|
+
@files_to_find.delete_if { |file| line.include?(file.name) }
|
45
|
+
end
|
41
46
|
end
|
42
|
-
end
|
47
|
+
end
|
data/spec/lib/sweeper_spec.rb
CHANGED
@@ -4,34 +4,42 @@ require 'lib/stowaway/sweeper'
|
|
4
4
|
|
5
5
|
describe Stowaway::Sweeper do
|
6
6
|
|
7
|
+
def sweeper(ignore = nil)
|
8
|
+
ig = ignore || [/^\./]
|
9
|
+
@sweeper ||= Stowaway::Sweeper.new(@files, @status_mock, ig)
|
10
|
+
end
|
11
|
+
|
7
12
|
before(:each) do
|
8
13
|
@f1 = Stowaway::FileObj.new('/fake/file1.jpg')
|
9
14
|
@f2 = Stowaway::FileObj.new('/fake/file2.gif')
|
10
15
|
@f3 = Stowaway::FileObj.new('/fake/file3.js')
|
11
16
|
@f4 = Stowaway::FileObj.new('/fake/also/file3.js')
|
12
17
|
@files = [@f1, @f2, @f3, @f4]
|
13
|
-
@
|
18
|
+
@status_mock = mock('status_mock', :null_object => true)
|
14
19
|
end
|
15
20
|
|
16
|
-
it "should sweep through directory
|
17
|
-
|
21
|
+
it "should sweep through directory looking for matches" do
|
22
|
+
sweeper.sweep('.')
|
18
23
|
@files.should be_empty
|
19
24
|
end
|
20
25
|
|
21
|
-
it "should not
|
22
|
-
|
23
|
-
|
26
|
+
it "should not sweep through ignored file types" do
|
27
|
+
sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data').length.should == 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should output a message when sweeping through a file" do
|
31
|
+
@status_mock.should_receive(:out).with("Sweeping: spec/data/testfile1.txt").once
|
32
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep('spec/data')
|
24
33
|
end
|
25
34
|
|
26
|
-
it "should
|
27
|
-
@
|
28
|
-
|
35
|
+
it "should flush the output after sweeping through a file" do
|
36
|
+
@status_mock.should_receive(:flush).once
|
37
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep('spec/data')
|
29
38
|
end
|
30
|
-
|
31
|
-
it "should remove matches
|
32
|
-
|
33
|
-
@
|
34
|
-
@files.should == [@f1]
|
39
|
+
|
40
|
+
it "should remove matches and leave files that were not found" do
|
41
|
+
sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data')
|
42
|
+
@files.should == [@f1, @f2]
|
35
43
|
end
|
36
44
|
|
37
|
-
end
|
45
|
+
end
|
data/stowaway.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stowaway}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Emilio Cavazos"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-07}
|
13
13
|
s.default_executable = %q{stowaway}
|
14
14
|
s.email = %q{ejcavazos@gmail.com}
|
15
15
|
s.executables = ["stowaway"]
|
@@ -18,20 +18,20 @@ Gem::Specification.new do |s|
|
|
18
18
|
"README.md"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
"
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
22
23
|
"README.md",
|
23
24
|
"Rakefile",
|
24
25
|
"TODO.txt",
|
25
26
|
"VERSION.yml",
|
26
|
-
"bin/.stowaway.swp",
|
27
27
|
"bin/stowaway",
|
28
28
|
"lib/stowaway/file.rb",
|
29
29
|
"lib/stowaway/fshelpyhelp.rb",
|
30
30
|
"lib/stowaway/locator.rb",
|
31
31
|
"lib/stowaway/options.rb",
|
32
32
|
"lib/stowaway/runner.rb",
|
33
|
+
"lib/stowaway/status.rb",
|
33
34
|
"lib/stowaway/sweeper.rb",
|
34
|
-
"pkg/stowaway-0.0.1.gem",
|
35
35
|
"spec/data/testfile1.txt",
|
36
36
|
"spec/data/testfile2.txt",
|
37
37
|
"spec/lib/file_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stowaway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emilio Cavazos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-07 00:00:00 -07:00
|
13
13
|
default_executable: stowaway
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,20 +23,20 @@ extra_rdoc_files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.md
|
25
25
|
files:
|
26
|
+
- .gitignore
|
26
27
|
- LICENSE
|
27
28
|
- README.md
|
28
29
|
- Rakefile
|
29
30
|
- TODO.txt
|
30
31
|
- VERSION.yml
|
31
|
-
- bin/.stowaway.swp
|
32
32
|
- bin/stowaway
|
33
33
|
- lib/stowaway/file.rb
|
34
34
|
- lib/stowaway/fshelpyhelp.rb
|
35
35
|
- lib/stowaway/locator.rb
|
36
36
|
- lib/stowaway/options.rb
|
37
37
|
- lib/stowaway/runner.rb
|
38
|
+
- lib/stowaway/status.rb
|
38
39
|
- lib/stowaway/sweeper.rb
|
39
|
-
- pkg/stowaway-0.0.1.gem
|
40
40
|
- spec/data/testfile1.txt
|
41
41
|
- spec/data/testfile2.txt
|
42
42
|
- spec/lib/file_spec.rb
|
data/bin/.stowaway.swp
DELETED
Binary file
|
data/pkg/stowaway-0.0.1.gem
DELETED
Binary file
|