stowaway 0.1.10 → 0.2.0

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/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 10
3
+ :minor: 2
4
+ :patch: 0
5
5
  :build:
@@ -1,7 +1,7 @@
1
1
  module FSHelpyHelp
2
- def ignore? file
3
- @ignore.each do |s|
4
- if file.match(/#{s}/i)
2
+ def ignore?(file)
3
+ @ignore.each do |exp|
4
+ if file.match(exp)
5
5
  return true
6
6
  end
7
7
  end
@@ -0,0 +1,20 @@
1
+ module Stowaway
2
+ module Output
3
+ RESET = "\r\e[0K"
4
+
5
+ def clr_print(msg)
6
+ print "#{RESET}#{msg}"
7
+ end
8
+
9
+ def flush
10
+ print RESET
11
+ $stdout.flush
12
+ end
13
+
14
+ def new_line(count = 1)
15
+ count.times do
16
+ print "\n"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -14,9 +14,12 @@ module Stowaway
14
14
  def run
15
15
  path = @options.path
16
16
  print "\nLocating files ... "
17
- files = @locator.find_all(path)
18
- print "#{files.length} files located\n"
19
- respond @sweeper.sweep(path, files)
17
+ assets = @locator.find_all(path)
18
+ print "#{assets.length} files located"
19
+ blank_lines
20
+ Dir.chdir(@options.path)
21
+ puts "sweeping: #{Dir.pwd}"
22
+ respond @sweeper.sweep(path, assets)
20
23
  end
21
24
 
22
25
  private
@@ -1,5 +1,5 @@
1
1
  require_relative "fshelpyhelp"
2
- require_relative "status"
2
+ require_relative "output"
3
3
  require_relative "matcher"
4
4
  require_relative "file"
5
5
  require "ostruct"
@@ -12,15 +12,16 @@ module Stowaway
12
12
 
13
13
  class Sweeper
14
14
  include FSHelpyHelp
15
+ include Output
15
16
 
16
- def initialize(status = Status.new, matcher = Matcher.new, ext_to_ignore = [])
17
- @status = status
17
+ def initialize(matcher = Matcher.new, ext_to_ignore = [])
18
18
  @matcher = matcher
19
- @ignore = ext_to_ignore || []
20
- @ignore += [/^\.|\.jpg$|\.jpeg$|\.gif$|\.png$|\.ico$|\.bmp$/i]
19
+ @ignore = ext_to_ignore
20
+ @ignore << /^\.|\.jpg$|\.jpeg$|\.gif$|\.png$|\.ico$|\.bmp$/i
21
21
  end
22
22
 
23
23
  def sweep(path, files=nil)
24
+ @root ||= path
24
25
  @result ||= OpenStruct.new({ :files => files, :name_only_matches => []})
25
26
 
26
27
  dir = Dir.new(path)
@@ -42,13 +43,15 @@ module Stowaway
42
43
  private
43
44
 
44
45
  def inspect_file(file)
45
- @status.out "Sweeping: #{file}"
46
- File.open(file, 'r') do |i|
46
+ root = @root.split("/").last
47
+ file_name = file.sub(/^.+\/(#{root})/, "")
48
+ clr_print(" => #{file_name}")
49
+ File.open(file, "r") do |i|
47
50
  while line = i.gets
48
51
  remove_match(line) #rescue nil
49
52
  end
50
53
  end
51
- @status.flush
54
+ flush
52
55
  end
53
56
 
54
57
  def remove_match(line)
@@ -0,0 +1,50 @@
1
+ require 'spec/spec_helper'
2
+ require 'lib/stowaway/output'
3
+
4
+ describe Stowaway::Output do
5
+
6
+ before(:each) do
7
+ @klass = Class.new do
8
+ include Stowaway::Output
9
+ end.new
10
+ end
11
+
12
+ describe "clr_print" do
13
+ it "should reset current line and print message" do
14
+ reset = "\r\e[0K"
15
+ msg = "yo yo sucka beeches!"
16
+ @klass.should_receive(:print).once.with("#{reset}#{msg}")
17
+ @klass.clr_print(msg)
18
+ end
19
+ end
20
+
21
+ describe "flush" do
22
+ it "should reset current line" do
23
+ @klass.should_receive(:print).once.with("\r\e[0K")
24
+ @klass.flush
25
+ end
26
+
27
+ it "should call flush on stdout" do
28
+ $stdout.should_receive(:flush)
29
+ @klass.flush
30
+ end
31
+ end
32
+
33
+ describe "new_line" do
34
+ it "should print 1 new line" do
35
+ @klass.should_receive(:print).once.with("\n")
36
+ @klass.new_line
37
+ end
38
+
39
+ it "should print 2 new lines" do
40
+ @klass.should_receive(:print).twice.with("\n")
41
+ @klass.new_line(2)
42
+ end
43
+
44
+ it "should print 8 new lines" do
45
+ @klass.should_receive(:print).exactly(8).times.with("\n")
46
+ @klass.new_line(8)
47
+ end
48
+ end
49
+
50
+ end
@@ -4,13 +4,15 @@ require "lib/stowaway/sweeper"
4
4
  require "lib/stowaway/matcher"
5
5
 
6
6
  describe Stowaway::Sweeper do
7
-
8
- def sweeper(ignore = nil)
9
- @sweeper ||= Stowaway::Sweeper.new(@status_mock, Stowaway::Matcher.new, ignore)
7
+
8
+ Stowaway::Output.class_eval do
9
+ def print str;end
10
10
  end
11
11
 
12
+ let(:sweeper) { Stowaway::Sweeper.new(Stowaway::Matcher.new, @ignore) }
13
+
12
14
  before(:each) do
13
- @status_mock = mock("status_mock", :null_object => true)
15
+ @ignore = [/^\.|\.rb$/]
14
16
  end
15
17
 
16
18
  it "should remove files when a reference to the file is found in source" do
@@ -26,36 +28,39 @@ describe Stowaway::Sweeper do
26
28
  end
27
29
 
28
30
  it "should not sweep through ignored file types" do
31
+ @ignore << /\.txt$/
29
32
  files = [Stowaway::FileObj.new("/fake/path1/button.jpg")]
30
- sweeper([/^\.|\.rb$|\.txt$/]).sweep("spec/data", files)
33
+ sweeper.sweep("spec/data", files)
31
34
  files.length.should == 1
32
35
  end
33
36
 
34
37
  it "should output a message when sweeping through a file" do
35
- @status_mock.should_receive(:out).with("Sweeping: spec/data/testfile1.txt").once
36
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data", [])
38
+ @ignore << /testfile2/
39
+ sweeper.should_receive(:clr_print).once.with(" => /testfile1.txt")
40
+ sweeper.sweep("spec/data", [])
37
41
  end
38
42
 
39
43
  it "should flush the output after sweeping through a file" do
40
- @status_mock.should_receive(:flush).once
41
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data", [])
44
+ @ignore << /testfile2/
45
+ sweeper.should_receive(:flush).once
46
+ sweeper.sweep("spec/data", [])
42
47
  end
43
48
 
44
49
  it "should files of the same name but with different paths as last resort" do
45
50
  files = [Stowaway::FileObj.new("/fake/path1/button.jpg"),
46
51
  Stowaway::FileObj.new("/fake/path2/button.jpg")]
47
- sweeper([/^\.|\.rb$/]).sweep("spec/data", files)
52
+ sweeper.sweep("spec/data", files)
48
53
  files.should be_empty
49
54
  end
50
55
 
51
56
  it "should add a file to an array of partially matched files when matched on name only" do
52
57
  files = [Stowaway::FileObj.new("/missing/button.jpg")]
53
- sweeper([/^\.|\.rb$/]).sweep("spec/data", files).should have(1).name_only_matches
58
+ sweeper.sweep("spec/data", files).should have(1).name_only_matches
54
59
  end
55
60
 
56
61
  it "should not remove files that were not found" do
57
62
  files = [Stowaway::FileObj.new("/a/stowaway.txt")]
58
- sweeper([/^\.|\.rb$/]).sweep("spec/data", files)
63
+ sweeper.sweep("spec/data", files)
59
64
  files.should_not be_empty
60
65
  files.first.fullpath.should == "/a/stowaway.txt"
61
66
  end
data/spec/runner_spec.rb CHANGED
@@ -1,30 +1,53 @@
1
1
  require 'spec/spec_helper'
2
2
  require 'lib/stowaway/runner'
3
3
 
4
+ class Stowaway::Status
5
+ # mock so I don't look at noise
6
+ def out(msg); end
7
+ def flush; end
8
+ end
9
+
4
10
  describe Stowaway::Runner do
5
11
 
6
12
  before(:each) do
7
- @argv = []
13
+ @argv = ["."]
14
+ @options = Stowaway::Options.new(@argv)
15
+ @locator = Stowaway::Locator.new(@options.file_types)
8
16
  end
9
17
 
10
18
  def runner
11
- options = Stowaway::Options.new(@argv)
12
- locator = Stowaway::Locator.new(options.file_types)
13
19
  sweeper = Stowaway::Sweeper.new
14
- @runner ||= Stowaway::Runner.new(options, locator, sweeper)
20
+ @runner ||= Stowaway::Runner.new(@options, @locator, sweeper)
15
21
  end
16
22
 
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
23
+ describe "output" do
24
+ it "should notify user that file location has begun" do
25
+ runner.should_receive(:print).with("\nLocating files ... ")
26
+ runner.should_receive(:print).any_number_of_times
27
+ runner.run
28
+ end
29
+
30
+ it "should notify user of the total number of files that were found" do
31
+ runner.should_receive(:print).with("0 files located")
32
+ runner.should_receive(:print).any_number_of_times
33
+ runner.run
34
+ end
35
+
36
+ it "should notify user that no stowaways were found when all files-to-find have been deleted" do
37
+ runner.should_receive(:print).with("Zero stowaways found. ")
38
+ runner.should_receive(:print).any_number_of_times
39
+ runner.run
40
+ end
41
+
42
+ it "should tell user how awesome their cleanliness is" do
43
+ runner.should_receive(:print).with("You run a tight ship.")
44
+ runner.should_receive(:print).any_number_of_times
45
+ runner.run
46
+ end
22
47
  end
23
48
 
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
49
+ it "should locate all assets" do
50
+ @locator.should_receive(:find_all).with(".").and_return([])
28
51
  runner.run
29
52
  end
30
53
  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.10"
8
+ s.version = "0.2.0"
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-23}
12
+ s.date = %q{2010-02-26}
13
13
  s.default_executable = %q{stowaway}
14
14
  s.email = %q{ejcavazos@gmail.com}
15
15
  s.executables = ["stowaway"]
@@ -30,8 +30,8 @@ Gem::Specification.new do |s|
30
30
  "lib/stowaway/locator.rb",
31
31
  "lib/stowaway/matcher.rb",
32
32
  "lib/stowaway/options.rb",
33
+ "lib/stowaway/output.rb",
33
34
  "lib/stowaway/runner.rb",
34
- "lib/stowaway/status.rb",
35
35
  "lib/stowaway/sweeper.rb",
36
36
  "spec/data/testfile1.txt",
37
37
  "spec/data/testfile2.txt",
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
39
39
  "spec/lib/locator_spec.rb",
40
40
  "spec/lib/matcher_spec.rb",
41
41
  "spec/lib/options_spec.rb",
42
+ "spec/lib/output_spec.rb",
42
43
  "spec/lib/sweeper_spec.rb",
43
44
  "spec/runner_spec.rb",
44
45
  "spec/spec.opts",
@@ -55,6 +56,7 @@ Gem::Specification.new do |s|
55
56
  "spec/lib/locator_spec.rb",
56
57
  "spec/lib/matcher_spec.rb",
57
58
  "spec/lib/options_spec.rb",
59
+ "spec/lib/output_spec.rb",
58
60
  "spec/lib/sweeper_spec.rb",
59
61
  "spec/runner_spec.rb",
60
62
  "spec/spec_helper.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.1.10
4
+ version: 0.2.0
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-23 00:00:00 -08:00
12
+ date: 2010-02-26 00:00:00 -08:00
13
13
  default_executable: stowaway
14
14
  dependencies: []
15
15
 
@@ -35,8 +35,8 @@ files:
35
35
  - lib/stowaway/locator.rb
36
36
  - lib/stowaway/matcher.rb
37
37
  - lib/stowaway/options.rb
38
+ - lib/stowaway/output.rb
38
39
  - lib/stowaway/runner.rb
39
- - lib/stowaway/status.rb
40
40
  - lib/stowaway/sweeper.rb
41
41
  - spec/data/testfile1.txt
42
42
  - spec/data/testfile2.txt
@@ -44,6 +44,7 @@ files:
44
44
  - spec/lib/locator_spec.rb
45
45
  - spec/lib/matcher_spec.rb
46
46
  - spec/lib/options_spec.rb
47
+ - spec/lib/output_spec.rb
47
48
  - spec/lib/sweeper_spec.rb
48
49
  - spec/runner_spec.rb
49
50
  - spec/spec.opts
@@ -82,6 +83,7 @@ test_files:
82
83
  - spec/lib/locator_spec.rb
83
84
  - spec/lib/matcher_spec.rb
84
85
  - spec/lib/options_spec.rb
86
+ - spec/lib/output_spec.rb
85
87
  - spec/lib/sweeper_spec.rb
86
88
  - spec/runner_spec.rb
87
89
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
- module Stowaway
2
- class Status
3
- RESET = "\r\e[0K"
4
- def out(msg)
5
- print "#{RESET}#{msg}"
6
- end
7
-
8
- def flush
9
- print RESET
10
- $stdout.flush
11
- end
12
- end
13
- end