torganiser 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/bin/torganiser +13 -3
- data/lib/torganiser/runner.rb +8 -3
- data/lib/torganiser/scanner.rb +20 -2
- data/lib/torganiser/version.rb +1 -1
- data/spec/torganiser/runner_spec.rb +16 -3
- data/spec/torganiser/scanner_spec.rb +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 350a58c7d89211f5d455326acb3dba3eafb3793a
|
4
|
+
data.tar.gz: 0c5fc030042cc4dd48cd109fd4e6d1e6d2e1dd3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f96dc70c919e05ff2bba01ad66e7ea35c74dd81fcfe23643c2d1623da9d403a9bc358a6cb2334fe3a7a98874b259d7142b6c2f068420ea33a59f16249acb3a4
|
7
|
+
data.tar.gz: b0017d3903fcaa9bb07cd81189d29ec16ce16648b8a8091b89a5af4b27688a2e2b954667c3021284137e9ff4d19caf6b64bc9662a0e2004b8401c794bbecf3fc
|
data/README.md
CHANGED
@@ -6,6 +6,7 @@ Simple utility that organises media files according to filename
|
|
6
6
|
[](https://travis-ci.org/sergei-matheson/torganiser)
|
7
7
|
[](https://codeclimate.com/github/sergei-matheson/torganiser)
|
8
8
|
[](https://codeclimate.com/github/sergei-matheson/torganiser)
|
9
|
+
[](http://badge.fury.io/rb/torganiser)
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
data/bin/torganiser
CHANGED
@@ -14,14 +14,24 @@ Clamp do
|
|
14
14
|
environment_variable: "TORGANISER_COLLECTION",
|
15
15
|
required: true
|
16
16
|
|
17
|
-
option ["--extension", "-e"], "EXTENSION",
|
17
|
+
option ["--extension", "-e"], "EXTENSION",
|
18
|
+
"Extension to include eg. mp4. May be specifed multiple times",
|
19
|
+
multivalued: true, attribute_name: :extensions
|
20
|
+
|
21
|
+
option ["--ignore", "-i"], "PATTERN",
|
22
|
+
"Ignore files whose path matches pattern eg. May be specifed multiple times.",
|
23
|
+
multivalued: true, attribute_name: :ignore
|
18
24
|
|
19
25
|
option "--dry-run", :flag, "If specified, no files will be moved"
|
20
26
|
|
21
|
-
parameter "FILES ...", "Files or directories to organise",
|
27
|
+
parameter "FILES ...", "Files or directories to organise",
|
28
|
+
attribute_name: :files
|
22
29
|
|
23
30
|
def execute
|
24
|
-
Torganiser::Runner.new(collection,
|
31
|
+
Torganiser::Runner.new(collection,
|
32
|
+
files: files, extensions: extensions,
|
33
|
+
ignored: ignore, dry_run: dry_run?
|
34
|
+
).run
|
25
35
|
end
|
26
36
|
|
27
37
|
end
|
data/lib/torganiser/runner.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
module Torganiser
|
2
2
|
# Runs the organisation process for a given array of
|
3
|
-
# files and
|
3
|
+
# files, extensions, and ignored files
|
4
4
|
class Runner
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
|
6
|
+
def initialize(
|
7
|
+
collection, files: [], extensions: [], ignored: [], dry_run: false
|
8
|
+
)
|
9
|
+
@scanner = Scanner.new(
|
10
|
+
files, extensions,
|
11
|
+
ignored.map { |string| Regexp.new(string) }
|
12
|
+
)
|
8
13
|
@arranger = Arranger.new(collection, dry_run: dry_run)
|
9
14
|
end
|
10
15
|
|
data/lib/torganiser/scanner.rb
CHANGED
@@ -5,12 +5,19 @@ module Torganiser
|
|
5
5
|
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
def initialize(files, extensions)
|
8
|
+
def initialize(files, extensions, ignored)
|
9
9
|
file_query.add_extension extensions
|
10
|
+
ignore ignored
|
10
11
|
add_files files
|
11
12
|
end
|
12
13
|
|
13
14
|
def each
|
15
|
+
all_files { |file| yield file unless ignored? file }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def all_files
|
14
21
|
ordinary_files.each do |file|
|
15
22
|
yield file
|
16
23
|
end
|
@@ -19,7 +26,18 @@ module Torganiser
|
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
22
|
-
|
29
|
+
def ignored? file
|
30
|
+
file = file.strip
|
31
|
+
@ignored_patterns.any? { |pattern| pattern.match file }
|
32
|
+
end
|
33
|
+
|
34
|
+
def ignore ignored
|
35
|
+
ignored_patterns.concat([*ignored])
|
36
|
+
end
|
37
|
+
|
38
|
+
def ignored_patterns
|
39
|
+
@ignored_patterns ||= []
|
40
|
+
end
|
23
41
|
|
24
42
|
def directory_files
|
25
43
|
if file_query.empty?
|
data/lib/torganiser/version.rb
CHANGED
@@ -9,11 +9,13 @@ module Torganiser
|
|
9
9
|
let(:collection) { double("collection") }
|
10
10
|
let(:files) { double("files") }
|
11
11
|
let(:extensions) { double("extensions") }
|
12
|
+
let(:ignored) { [] }
|
12
13
|
|
13
14
|
subject do
|
14
15
|
Runner.new(
|
15
16
|
collection,
|
16
|
-
files: files, extensions: extensions,
|
17
|
+
files: files, extensions: extensions,
|
18
|
+
ignored: ignored, dry_run: true
|
17
19
|
)
|
18
20
|
end
|
19
21
|
|
@@ -27,8 +29,19 @@ module Torganiser
|
|
27
29
|
|
28
30
|
describe "a scanner" do
|
29
31
|
|
30
|
-
it "is created for the files and
|
31
|
-
expect(Scanner).to receive(:new).with(
|
32
|
+
it "is created for the files, extensions, and ignored as regex" do
|
33
|
+
expect(Scanner).to receive(:new).with(
|
34
|
+
files, extensions, anything
|
35
|
+
)
|
36
|
+
subject.run
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:ignored) { ["ignored", ".*stuff.*"] }
|
40
|
+
|
41
|
+
it "is given the list of files to ignore converted to regex" do
|
42
|
+
expect(Scanner).to receive(:new).with(
|
43
|
+
anything, anything, [/ignored/, /.*stuff.*/]
|
44
|
+
)
|
32
45
|
subject.run
|
33
46
|
end
|
34
47
|
|
@@ -10,7 +10,9 @@ module Torganiser
|
|
10
10
|
|
11
11
|
let(:extensions) { double("extensions") }
|
12
12
|
|
13
|
-
|
13
|
+
let(:ignored_patterns) { [] }
|
14
|
+
|
15
|
+
subject { Scanner.new(files, extensions, ignored_patterns) }
|
14
16
|
|
15
17
|
let(:query_pattern) { double("query pattern") }
|
16
18
|
|
@@ -77,7 +79,7 @@ module Torganiser
|
|
77
79
|
end
|
78
80
|
|
79
81
|
it "enumerates the ordinary files, and files found in the directories" do
|
80
|
-
expect { |
|
82
|
+
expect { |block| subject.each(&block) }.to yield_successive_args(
|
81
83
|
"/tmp/file1",
|
82
84
|
"/tmp/file2",
|
83
85
|
"/tmp/dir1/file3",
|
@@ -85,6 +87,28 @@ module Torganiser
|
|
85
87
|
)
|
86
88
|
end
|
87
89
|
|
90
|
+
context "if any files match any of the ignore patterns" do
|
91
|
+
let(:ignored_patterns) { [/ignoreme/, /alsoignorethis$/] }
|
92
|
+
|
93
|
+
let(:query_results) do
|
94
|
+
[
|
95
|
+
"/tmp/dir2/file5.alsoignorethis\r\n",
|
96
|
+
"/tmp/dir1", "/tmp/dir2/file5.ignoreme",
|
97
|
+
"/tmp/dir1/file3", "/tmp/dir2",
|
98
|
+
"/tmp/dir2/file4"
|
99
|
+
]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "does not include the ignored files" do
|
103
|
+
expect { |block| subject.each(&block) }.to yield_successive_args(
|
104
|
+
"/tmp/file1",
|
105
|
+
"/tmp/file2",
|
106
|
+
"/tmp/dir1/file3",
|
107
|
+
"/tmp/dir2/file4"
|
108
|
+
)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
88
112
|
|
89
113
|
end
|
90
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torganiser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|