stowaway 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/TODO.txt +1 -2
- data/VERSION.yml +1 -1
- data/bin/stowaway +5 -1
- data/lib/stowaway/locator.rb +12 -13
- data/lib/stowaway/options.rb +25 -18
- data/lib/stowaway/runner.rb +8 -9
- data/lib/stowaway/sweeper.rb +9 -3
- data/spec/lib/sweeper_spec.rb +21 -22
- data/spec/runner_spec.rb +25 -3
- data/stowaway.gemspec +2 -2
- metadata +2 -2
data/TODO.txt
CHANGED
data/VERSION.yml
CHANGED
data/bin/stowaway
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'lib/stowaway/runner'
|
4
|
-
|
4
|
+
|
5
|
+
options = Stowaway::Options.new(ARGV)
|
6
|
+
locator = Stowaway::Locator.new(options.file_types)
|
7
|
+
sweeper = Stowaway::Sweeper.new
|
8
|
+
runner = Stowaway::Runner.new(options, locator, sweeper)
|
5
9
|
runner.run
|
data/lib/stowaway/locator.rb
CHANGED
@@ -4,29 +4,22 @@ require_relative 'file'
|
|
4
4
|
module Stowaway
|
5
5
|
class Locator
|
6
6
|
include FSHelpyHelp
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(extensions)
|
9
9
|
@extensions = extensions
|
10
10
|
@ignore = [/^\./]
|
11
11
|
end
|
12
|
-
|
13
|
-
def type?(file)
|
14
|
-
@extensions.each do |e|
|
15
|
-
return true if file.match(/#{e}$/)
|
16
|
-
end
|
17
|
-
false
|
18
|
-
end
|
19
|
-
|
12
|
+
|
20
13
|
def find_all(path, files = [])
|
21
14
|
@root = path if @root.nil?
|
22
15
|
|
23
16
|
dir = Dir.new(path)
|
24
|
-
|
17
|
+
|
25
18
|
dir.each do |f|
|
26
19
|
next if ignore?(f)
|
27
|
-
|
20
|
+
|
28
21
|
file = File.join(dir.path, f)
|
29
|
-
|
22
|
+
|
30
23
|
if File.directory?(file)
|
31
24
|
find_all file, files
|
32
25
|
elsif type?(f)
|
@@ -35,6 +28,12 @@ module Stowaway
|
|
35
28
|
end
|
36
29
|
files
|
37
30
|
end
|
38
|
-
|
31
|
+
|
32
|
+
def type?(file)
|
33
|
+
@extensions.each do |e|
|
34
|
+
return true if file.match(/#{e}$/)
|
35
|
+
end
|
36
|
+
false
|
37
|
+
end
|
39
38
|
end
|
40
39
|
end
|
data/lib/stowaway/options.rb
CHANGED
@@ -8,34 +8,41 @@ module Stowaway
|
|
8
8
|
|
9
9
|
def initialize(argv)
|
10
10
|
@file_types = DEFAULT_FILE_TYPES
|
11
|
-
|
12
|
-
|
11
|
+
@argv = argv
|
12
|
+
parse
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
|
+
def parse
|
17
|
+
OptionParser.new do |opts|
|
18
|
+
opts.banner = "Usage: stowaway [ options ] path/to/site"
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
opts.banner = "Usage: stowaway [ options ] path/to/site"
|
20
|
-
|
21
|
-
opts.on("-t", "--types <TYPES>", String, "File types to search for (ex: .jpg .gif)") do |ext|
|
22
|
-
@file_types = ext.split(' ')
|
23
|
-
end
|
20
|
+
parse_types(opts)
|
21
|
+
parse_help(opts)
|
24
22
|
|
25
|
-
opts.on("-h", "--help", "Show this message") do
|
26
|
-
puts opts
|
27
|
-
exit
|
28
|
-
end
|
29
|
-
|
30
23
|
begin
|
31
|
-
argv = ["-h"] if argv.empty?
|
32
|
-
opts.parse!(argv)
|
24
|
+
@argv = ["-h"] if @argv.empty?
|
25
|
+
opts.parse!(@argv)
|
33
26
|
rescue OptionParser::ParseError => e
|
34
27
|
STDERR.puts e.message, "\n", opts
|
35
28
|
exit(-1)
|
36
29
|
end
|
37
|
-
|
30
|
+
|
31
|
+
@path = @argv[0]
|
38
32
|
end
|
39
33
|
end
|
40
|
-
|
34
|
+
|
35
|
+
def parse_types opts
|
36
|
+
opts.on("-t", "--types <TYPES>", String, "File types to search for (ex: .jpg .gif)") do |ext|
|
37
|
+
@file_types = ext.split(' ')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_help opts
|
42
|
+
opts.on("-h", "--help", "Show this message") do
|
43
|
+
puts opts
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
41
48
|
end
|
data/lib/stowaway/runner.rb
CHANGED
@@ -5,19 +5,18 @@ require_relative 'sweeper'
|
|
5
5
|
module Stowaway
|
6
6
|
class Runner
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@options =
|
8
|
+
def initialize(options, locator, sweeper)
|
9
|
+
@options = options
|
10
|
+
@locator = locator
|
11
|
+
@sweeper = sweeper
|
10
12
|
end
|
11
13
|
|
12
14
|
def run
|
15
|
+
path = @options.path
|
13
16
|
print "\nLocating files ... "
|
14
|
-
|
15
|
-
files
|
16
|
-
@
|
17
|
-
p "#{@total} files located"
|
18
|
-
|
19
|
-
fs = Stowaway::Sweeper.new files
|
20
|
-
respond fs.sweep @options.path
|
17
|
+
files = @locator.find_all(path)
|
18
|
+
print "#{files.length} files located\n"
|
19
|
+
respond @sweeper.sweep(path, files)
|
21
20
|
end
|
22
21
|
|
23
22
|
private
|
data/lib/stowaway/sweeper.rb
CHANGED
@@ -5,18 +5,24 @@ require_relative "file"
|
|
5
5
|
require "ostruct"
|
6
6
|
|
7
7
|
module Stowaway
|
8
|
+
|
9
|
+
# Sweeper will sweep through a directory recursively (path) and try to find
|
10
|
+
# references to files in the array of FileObjs passed in as the second
|
11
|
+
# parameter.
|
12
|
+
|
8
13
|
class Sweeper
|
9
14
|
include FSHelpyHelp
|
10
15
|
|
11
|
-
def initialize(
|
12
|
-
@result = OpenStruct.new({ :files => files, :name_only_matches => []})
|
16
|
+
def initialize(status = Status.new, matcher = Matcher.new, ext_to_ignore = [])
|
13
17
|
@status = status
|
14
18
|
@matcher = matcher
|
15
19
|
@ignore = ext_to_ignore || []
|
16
20
|
@ignore += [/^\.|\.jpg$|\.jpeg$|\.gif$|\.png$|\.ico$|\.bmp$/i]
|
17
21
|
end
|
18
22
|
|
19
|
-
def sweep(path)
|
23
|
+
def sweep(path, files=nil)
|
24
|
+
@result ||= OpenStruct.new({ :files => files, :name_only_matches => []})
|
25
|
+
|
20
26
|
dir = Dir.new(path)
|
21
27
|
|
22
28
|
dir.each do |f|
|
data/spec/lib/sweeper_spec.rb
CHANGED
@@ -6,59 +6,58 @@ require "lib/stowaway/matcher"
|
|
6
6
|
describe Stowaway::Sweeper do
|
7
7
|
|
8
8
|
def sweeper(ignore = nil)
|
9
|
-
@sweeper ||= Stowaway::Sweeper.new(@
|
9
|
+
@sweeper ||= Stowaway::Sweeper.new(@status_mock, Stowaway::Matcher.new, ignore)
|
10
10
|
end
|
11
11
|
|
12
12
|
before(:each) do
|
13
|
-
@files = []
|
14
13
|
@status_mock = mock("status_mock", :null_object => true)
|
15
14
|
end
|
16
15
|
|
17
16
|
it "should remove files when a reference to the file is found in source" do
|
18
|
-
|
19
|
-
sweeper.sweep("spec/data")
|
20
|
-
|
17
|
+
files = [Stowaway::FileObj.new("/fake/path1/button.jpg")]
|
18
|
+
sweeper.sweep("spec/data", files)
|
19
|
+
files.should be_empty
|
21
20
|
end
|
22
21
|
|
23
22
|
it "should return an OpenStruct with the result of the sweeping" do
|
24
|
-
result = sweeper.sweep("spec/data")
|
23
|
+
result = sweeper.sweep("spec/data", [])
|
25
24
|
result.files.should be_an_instance_of Array
|
26
25
|
result.name_only_matches.should be_an_instance_of Array
|
27
26
|
end
|
28
27
|
|
29
28
|
it "should not sweep through ignored file types" do
|
30
|
-
|
31
|
-
sweeper([/^\.|\.rb$|\.txt$/]).sweep("spec/data")
|
32
|
-
|
29
|
+
files = [Stowaway::FileObj.new("/fake/path1/button.jpg")]
|
30
|
+
sweeper([/^\.|\.rb$|\.txt$/]).sweep("spec/data", files)
|
31
|
+
files.length.should == 1
|
33
32
|
end
|
34
33
|
|
35
34
|
it "should output a message when sweeping through a file" do
|
36
35
|
@status_mock.should_receive(:out).with("Sweeping: spec/data/testfile1.txt").once
|
37
|
-
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
36
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data", [])
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should flush the output after sweeping through a file" do
|
41
40
|
@status_mock.should_receive(:flush).once
|
42
|
-
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
41
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data", [])
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should files of the same name but with different paths as last resort" do
|
46
|
-
|
47
|
-
|
48
|
-
sweeper([/^\.|\.rb$/]).sweep("spec/data")
|
49
|
-
|
45
|
+
files = [Stowaway::FileObj.new("/fake/path1/button.jpg"),
|
46
|
+
Stowaway::FileObj.new("/fake/path2/button.jpg")]
|
47
|
+
sweeper([/^\.|\.rb$/]).sweep("spec/data", files)
|
48
|
+
files.should be_empty
|
50
49
|
end
|
51
50
|
|
52
|
-
it "should add a file
|
53
|
-
|
54
|
-
sweeper([/^\.|\.rb$/]).sweep("spec/data").should have(1).name_only_matches
|
51
|
+
it "should add a file to an array of partially matched files when matched on name only" do
|
52
|
+
files = [Stowaway::FileObj.new("/missing/button.jpg")]
|
53
|
+
sweeper([/^\.|\.rb$/]).sweep("spec/data", files).should have(1).name_only_matches
|
55
54
|
end
|
56
55
|
|
57
56
|
it "should not remove files that were not found" do
|
58
|
-
|
59
|
-
sweeper([/^\.|\.rb$/]).sweep("spec/data")
|
60
|
-
|
61
|
-
|
57
|
+
files = [Stowaway::FileObj.new("/a/stowaway.txt")]
|
58
|
+
sweeper([/^\.|\.rb$/]).sweep("spec/data", files)
|
59
|
+
files.should_not be_empty
|
60
|
+
files.first.fullpath.should == "/a/stowaway.txt"
|
62
61
|
end
|
63
62
|
|
64
63
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -2,7 +2,29 @@ require 'spec/spec_helper'
|
|
2
2
|
require 'lib/stowaway/runner'
|
3
3
|
|
4
4
|
describe Stowaway::Runner do
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@argv = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def runner
|
11
|
+
options = Stowaway::Options.new(@argv)
|
12
|
+
locator = Stowaway::Locator.new(options.file_types)
|
13
|
+
sweeper = Stowaway::Sweeper.new
|
14
|
+
@runner ||= Stowaway::Runner.new(options, locator, sweeper)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should notify user that file location has begun" do
|
18
|
+
@argv << "."
|
19
|
+
runner.should_receive(:print).with("\nLocating files ... ")
|
20
|
+
runner.should_receive(:print).any_number_of_times
|
21
|
+
runner.run
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should notify user of the total number of files that were found" do
|
25
|
+
@argv << "."
|
26
|
+
runner.should_receive(:print).with("0 files located\n").any_number_of_times
|
27
|
+
runner.should_receive(:print).any_number_of_times
|
28
|
+
runner.run
|
7
29
|
end
|
8
|
-
end
|
30
|
+
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.1.
|
8
|
+
s.version = "0.1.10"
|
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{2010-02-
|
12
|
+
s.date = %q{2010-02-23}
|
13
13
|
s.default_executable = %q{stowaway}
|
14
14
|
s.email = %q{ejcavazos@gmail.com}
|
15
15
|
s.executables = ["stowaway"]
|
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.1.
|
4
|
+
version: 0.1.10
|
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: 2010-02-
|
12
|
+
date: 2010-02-23 00:00:00 -08:00
|
13
13
|
default_executable: stowaway
|
14
14
|
dependencies: []
|
15
15
|
|