rugsweep 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjNjZDlmNzgyNjA3YzJlOWU0ZTRjM2U0ZDc3ODNmODQ4MGU3ZTk2NA==
5
+ data.tar.gz: !binary |-
6
+ ZDIyOTRjMGY0OGVjMWNkM2U2MDlmYWQ4MWNmNzZkNGYxYTRhYzE4NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTgyNGRiYzhkMGQ1NzY1ZTA4NDM5YzExMWIwNGQzYjAxNDBmZWMwZDk1ZWEw
10
+ ZGNjMGMzODdjMjc2YjgxOWUwMzRmMGY0NmMwOTRlNmE0Yjk2MjA5MjFmMzAw
11
+ OTg4YTE0ZTI0ZjQ0MTM3ODA1YjFkNWNiZDZjZjJkODQwODg0NTg=
12
+ data.tar.gz: !binary |-
13
+ OGI2NjZmODNlZTBjYWExZTRmNDE0ZTIyMWQ4NGU4ZmYzN2U2NDI5N2ZmMDRl
14
+ NzJhNGZmMjU3NmUwMGFlYjRhZDZkYzFiMTExZTg5YTFhZjY0OGFmYTIwZTI0
15
+ MDMxZTc5ZjAxYmUxYTQ2NTMwZjQwOGYxYmVhMzkyYzBiNDAzNmE=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,11 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/RegexpLiteral:
5
+ MaxSlashes: 0
6
+
7
+ Style/StringLiterals:
8
+ Enabled: false
9
+
10
+ Style/TrailingComma:
11
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rugsweep.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jonathon M. Abbott
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # Rugsweep
2
+
3
+ [![Build Status](https://travis-ci.org/JonathonMA/rugsweep.svg?branch=master)](https://travis-ci.org/JonathonMA/rugsweep)
4
+
5
+ Sweeps files under the rug.
6
+
7
+ ## Installation
8
+
9
+ Install it using rubygems:
10
+
11
+ $ gem install rugsweep
12
+
13
+ ## Usage
14
+
15
+ Create a configuration file: *not implemented yet*
16
+
17
+ $ rugsweep init --rug=tmp GoodFile1 GoodFile2
18
+
19
+ Now you can sweep things under the rug:
20
+
21
+ $ ls
22
+ GoodFile1
23
+ GoodFile2
24
+ BadFile
25
+ BadFile2
26
+
27
+ $ rugsweep
28
+ (M) BadFile
29
+ (M) BadFile2
30
+
31
+ $ ls
32
+ GoodFile1
33
+ GoodFile2
34
+
35
+ $ ls tmp
36
+ BadFile
37
+ BadFile2
38
+
39
+ You can mark additional "good" files using ok *not implemented yet*
40
+
41
+ $ rugsweep ok GoodFile3
42
+
43
+ ## TODO
44
+
45
+ 1. init
46
+ 2. ok
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/JonathonMA/rugsweep/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: [
9
+ :spec,
10
+ :rubocop,
11
+ ]
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rugsweep'
4
+
5
+ Rugsweep.sweep
@@ -0,0 +1,9 @@
1
+ require "rugsweep/version"
2
+
3
+ module Rugsweep
4
+ def self.sweep
5
+ Sweeper.new.sweep
6
+ end
7
+ end
8
+
9
+ require "rugsweep/sweeper"
@@ -0,0 +1,97 @@
1
+ require "fileutils"
2
+ require "yaml"
3
+ require "paint"
4
+ require "pathname"
5
+
6
+ module Rugsweep
7
+ class Sweeper
8
+ def initialize(logger = STDOUT)
9
+ @logger = logger
10
+ end
11
+
12
+ def log(str)
13
+ @logger.puts str
14
+ end
15
+
16
+ def log_action(action, color, entry)
17
+ log format("(%s) %s", Paint[action, color], entry)
18
+ end
19
+
20
+ def log_existing(entry, _target)
21
+ log_action 'S', :yellow, entry
22
+ end
23
+
24
+ def log_move(entry, _target)
25
+ log_action 'M', :green, entry
26
+ end
27
+
28
+ def sweep
29
+ ensure_dumping_ground_exists
30
+ filtered_entries.each do |entry|
31
+ target = dumping_ground.join(entry.basename)
32
+ if target.exist?
33
+ log_existing(entry, target)
34
+ else
35
+ log_move(entry, target)
36
+ FileUtils.mv entry, dumping_ground
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def ensure_dumping_ground_exists
44
+ dumping_ground.directory? || dumping_ground.mkdir
45
+ end
46
+
47
+ CONFIG_FILE = ".rugsweep.yml"
48
+
49
+ def base
50
+ Pathname.new(".")
51
+ end
52
+
53
+ def entries
54
+ base.children
55
+ end
56
+
57
+ def filtered_entries
58
+ entries.reject do |entry|
59
+ filter = Filter.new(entry, keep_files)
60
+ filter.dotfile? || filter.ok?
61
+ end
62
+ end
63
+
64
+ def config
65
+ @config ||= File.open(CONFIG_FILE) { |f| YAML.load(f) }
66
+ end
67
+
68
+ def dumping_ground
69
+ @dumping_ground ||= base.join config.fetch("rug")
70
+ end
71
+
72
+ def keep_files
73
+ @keep_files ||= config.fetch("keep") + [dumping_ground.basename.to_s]
74
+ end
75
+ end
76
+
77
+ class Filter
78
+ def initialize(path, keepfiles)
79
+ @path = path
80
+ @keepfiles = keepfiles
81
+ end
82
+
83
+ def dotfile?
84
+ filename.start_with? "."
85
+ end
86
+
87
+ def ok?
88
+ @keepfiles.include? filename
89
+ end
90
+
91
+ private
92
+
93
+ def filename
94
+ @path.basename.to_s
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module Rugsweep
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rugsweep/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rugsweep"
8
+ spec.version = Rugsweep::VERSION
9
+ spec.authors = ["Jonathon M. Abbott"]
10
+ spec.email = ["jonathona@everydayhero.com.au"]
11
+ spec.summary = "sweep files under the rug"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/JonathonMA/rugsweep"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "paint", "~> 0.8.7"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.1.0"
26
+ spec.add_development_dependency "rubocop", "~> 0.27.0"
27
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rugsweep'
4
+
5
+ require 'yaml'
6
+ require 'tmpdir'
7
+ require 'stringio'
8
+
9
+ describe Rugsweep do
10
+ it 'has a version number' do
11
+ expect(Rugsweep::VERSION).not_to be nil
12
+ end
13
+
14
+ def prepare_test_dir(dir, config, files)
15
+ Dir.chdir(dir) do
16
+ files.each do |file|
17
+ IO.write file, ""
18
+ end
19
+ File.open(".rugsweep.yml", "w") { |f| YAML.dump(config, f) }
20
+ end
21
+ end
22
+
23
+ let!(:dir) { Dir.mktmpdir }
24
+
25
+ after(:each) do
26
+ FileUtils.remove_entry_secure dir
27
+ end
28
+
29
+ def assert_file_present(filename)
30
+ path = Pathname.new(filename)
31
+ expect(path).to exist
32
+ end
33
+
34
+ def assert_file_absent(filename)
35
+ path = Pathname.new(filename)
36
+ expect(path).to_not exist
37
+ end
38
+
39
+ let(:log) { StringIO.new }
40
+
41
+ it "should clean a directory" do
42
+ config = {
43
+ "keep" => %w(
44
+ Good
45
+ Good2
46
+ ),
47
+ "rug" => "tmp",
48
+ }
49
+ files = %w( Good Good2 Bad Bad2 .Other )
50
+
51
+ prepare_test_dir(dir, config, files)
52
+
53
+ Dir.chdir(dir) do
54
+ files.each do |file|
55
+ assert_file_present(file)
56
+ end
57
+ Rugsweep::Sweeper.new(log).sweep
58
+ assert_file_present("Good")
59
+ assert_file_present("Good2")
60
+ assert_file_absent("Bad")
61
+ assert_file_absent("Bad2")
62
+ assert_file_present("tmp/Bad")
63
+ assert_file_present("tmp/Bad2")
64
+ expect(log.string).to include("Bad")
65
+ expect(log.string).to include("Bad2")
66
+ expect(log.string).to_not include("Good")
67
+ expect(log.string).to_not include("Good2")
68
+ end
69
+ end
70
+
71
+ it "should raise when no config file" do
72
+ Dir.chdir(dir) do
73
+ expect do
74
+ Rugsweep::Sweeper.new(log).sweep
75
+ end.to raise_error
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rugsweep'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rugsweep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathon M. Abbott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.27.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.27.0
83
+ description: sweep files under the rug
84
+ email:
85
+ - jonathona@everydayhero.com.au
86
+ executables:
87
+ - rugsweep
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .rubocop.yml
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/rugsweep
100
+ - lib/rugsweep.rb
101
+ - lib/rugsweep/sweeper.rb
102
+ - lib/rugsweep/version.rb
103
+ - rugsweep.gemspec
104
+ - spec/rugsweep_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/JonathonMA/rugsweep
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: sweep files under the rug
130
+ test_files:
131
+ - spec/rugsweep_spec.rb
132
+ - spec/spec_helper.rb