classifile 0.1.0 → 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.
- checksums.yaml +4 -4
- data/.idea/classifile.iml +41 -3
- data/Gemfile +2 -0
- data/README.md +28 -0
- data/classifile.gemspec +1 -0
- data/lib/classifile/checker/assert_checker.rb +1 -0
- data/lib/classifile/const/file_types.rb +2 -2
- data/lib/classifile/const/version.rb +1 -1
- data/lib/classifile/execute.rb +19 -9
- data/lib/classifile/result/move_file.rb +14 -0
- data/lib/classifile/result/remove_file.rb +8 -0
- data/lib/classifile/result/result.rb +14 -0
- data/lib/classifile/state.rb +34 -13
- data/lib/classifile.rb +3 -1
- data/sandbox/dsl/dsl.rb +4 -0
- data/sandbox/from/remove.tmp +0 -0
- metadata +20 -3
- data/lib/classifile/from_to.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cce93eb73710a688753be83c9cb3d8e4b52b53b0d2331fc5e0a8089189da42b
|
|
4
|
+
data.tar.gz: aea6312d952170098e7137d37fe1ca71ee3e2431081f29f57bf1d10cb3bbf8f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d1c5ef63757218780334243155a69fe0eda53b5f0c11a23c14ecb378265797c4481e65959b7581a1cbbc8e9288aea0ec4ad8046479052e9251540e854e3d9a7
|
|
7
|
+
data.tar.gz: e6f80dd7ef81e0922adcfa2e93d54d2d9ee03b1a00f98f9013b72254b6ccd0705b40bc525c78764757f99b26241fd3334ea97b053ace996b1cb272d315337553
|
data/.idea/classifile.iml
CHANGED
|
@@ -13,22 +13,60 @@
|
|
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
14
14
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, ruby-3.0.2-p107) [gem]" level="application" />
|
|
15
15
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.27, ruby-3.0.2-p107) [gem]" level="application" />
|
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, ruby-3.0.2-p107) [gem]" level="application" />
|
|
17
18
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.20.1, ruby-3.0.2-p107) [gem]" level="application" />
|
|
18
19
|
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
19
20
|
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.
|
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-3.0.2-p107) [gem]" level="application" />
|
|
21
22
|
<orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4, ruby-3.0.2-p107) [gem]" level="application" />
|
|
22
23
|
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, ruby-3.0.2-p107) [gem]" level="application" />
|
|
23
24
|
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, ruby-3.0.2-p107) [gem]" level="application" />
|
|
24
25
|
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.20.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
25
26
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.11.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
26
27
|
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, ruby-3.0.2-p107) [gem]" level="application" />
|
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, ruby-3.0.2-p107) [gem]" level="application" />
|
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.3, ruby-3.0.2-p107) [gem]" level="application" />
|
|
27
31
|
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.0.0, ruby-3.0.2-p107) [gem]" level="application" />
|
|
28
32
|
</component>
|
|
29
33
|
<component name="RakeTasksCache">
|
|
30
34
|
<option name="myRootTask">
|
|
31
|
-
<RakeTaskImpl id="rake"
|
|
35
|
+
<RakeTaskImpl id="rake">
|
|
36
|
+
<subtasks>
|
|
37
|
+
<RakeTaskImpl description="Build classifile-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
|
38
|
+
<RakeTaskImpl id="build">
|
|
39
|
+
<subtasks>
|
|
40
|
+
<RakeTaskImpl description="Generate SHA512 checksum if classifile-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
|
41
|
+
</subtasks>
|
|
42
|
+
</RakeTaskImpl>
|
|
43
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
|
44
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
|
45
|
+
<RakeTaskImpl description="Build and install classifile-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
|
46
|
+
<RakeTaskImpl id="install">
|
|
47
|
+
<subtasks>
|
|
48
|
+
<RakeTaskImpl description="Build and install classifile-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
|
49
|
+
</subtasks>
|
|
50
|
+
</RakeTaskImpl>
|
|
51
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push classifile-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
|
52
|
+
<RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
|
|
53
|
+
<RakeTaskImpl id="rubocop">
|
|
54
|
+
<subtasks>
|
|
55
|
+
<RakeTaskImpl description="Auto-correct RuboCop offenses" fullCommand="rubocop:auto_correct" id="auto_correct" />
|
|
56
|
+
</subtasks>
|
|
57
|
+
</RakeTaskImpl>
|
|
58
|
+
<RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
|
|
59
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
|
60
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
|
61
|
+
<RakeTaskImpl id="release">
|
|
62
|
+
<subtasks>
|
|
63
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
|
64
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
|
65
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
|
66
|
+
</subtasks>
|
|
67
|
+
</RakeTaskImpl>
|
|
68
|
+
</subtasks>
|
|
69
|
+
</RakeTaskImpl>
|
|
32
70
|
</option>
|
|
33
71
|
</component>
|
|
34
72
|
</module>
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# Classifile
|
|
2
2
|
|
|
3
|
+
[](https://github.com/kurehajime/classifile/actions/workflows/main_test.yml)
|
|
4
|
+
|
|
3
5
|
Classifile is a tool for classifying files by Ruby DSL.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
8
|
+
Ruby 3.0.0 or higher is required.
|
|
6
9
|
|
|
7
10
|
$ gem install classifile
|
|
8
11
|
|
|
@@ -68,6 +71,19 @@ temp/
|
|
|
68
71
|
└─dancing_cat.mpg
|
|
69
72
|
```
|
|
70
73
|
|
|
74
|
+
## Options
|
|
75
|
+
|
|
76
|
+
Command line options are here.
|
|
77
|
+
|
|
78
|
+
| Sort option | Long option | Description |
|
|
79
|
+
| ---- | ---- |---- |
|
|
80
|
+
| -d *PATH* | --dsl *PATH* |DSL path |
|
|
81
|
+
| -f *PATH* | --from *PATH* |Source directory path |
|
|
82
|
+
| -t *PATH* | --to *PATH* |Output directory path |
|
|
83
|
+
| -p | --preview |Preview Mode(don't move,don't copy) |
|
|
84
|
+
| -c | --copy |Copy Mode(don't move) |
|
|
85
|
+
| -h | --help |Show this help |
|
|
86
|
+
|
|
71
87
|
## Syntax
|
|
72
88
|
|
|
73
89
|
### Classifile rules.
|
|
@@ -108,6 +124,18 @@ end
|
|
|
108
124
|
|
|
109
125
|
`dog.png -> /Dogs/dog.png`
|
|
110
126
|
|
|
127
|
+
#### del block
|
|
128
|
+
|
|
129
|
+
`del` block deletes the file.
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
del do
|
|
133
|
+
end_with? ".tmp"
|
|
134
|
+
end
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`temp.tmp will be deleted.`
|
|
138
|
+
|
|
111
139
|
### Check methods
|
|
112
140
|
|
|
113
141
|
The check method checks if the file should be stored in that directory.
|
data/classifile.gemspec
CHANGED
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
|
|
35
35
|
spec.add_development_dependency "rake", ">= 13.0"
|
|
36
36
|
spec.add_development_dependency "rubocop", ">= 1.7"
|
|
37
|
+
spec.add_development_dependency "simplecov", ">= 0.21"
|
|
37
38
|
|
|
38
39
|
# For more information and examples about making a new gem, checkout our
|
|
39
40
|
# guide at: "https://github.com/kurehajime/classifile"
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
# extension
|
|
5
5
|
module Classifile
|
|
6
6
|
FILE_TYPE_IMAGE = %w[.gif .jpg .jpeg .jpe .jfif .png .bmp .dib .rle .ico .ai .art .psd .tif .tiff .nsk .webp].freeze
|
|
7
|
-
FILE_TYPE_SOUND = %w[.mp3 .wma .
|
|
8
|
-
FILE_TYPE_MOVIE = %w[.avi .flv .mpg .mpeg .mp4 .mkv .mov .qt .wmv .asf .m2ts .ts .
|
|
7
|
+
FILE_TYPE_SOUND = %w[.mp3 .wma .3gp .3g2 .aac .ogg .oga .m4a .alac .flac .wav].freeze
|
|
8
|
+
FILE_TYPE_MOVIE = %w[.avi .flv .mpg .mpeg .mp4 .mkv .mov .qt .wmv .asf .m2ts .ts .webm .ogm].freeze
|
|
9
9
|
end
|
data/lib/classifile/execute.rb
CHANGED
|
@@ -9,17 +9,24 @@ module Classifile
|
|
|
9
9
|
# However, it does not actually move the file,
|
|
10
10
|
# but outputs the mv command as a string.
|
|
11
11
|
def test(dsl_path, from_paths, to_path)
|
|
12
|
-
classify(dsl_path, from_paths, to_path).each do |
|
|
13
|
-
puts "mv \"#{
|
|
12
|
+
classify(dsl_path, from_paths, to_path).each do |result|
|
|
13
|
+
puts "mv \"#{result.from}\" \"#{result.to}\" " if result.is_a? MoveFile
|
|
14
|
+
puts "rm \"#{result.from}\" " if result.is_a? RemoveFile
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
##
|
|
18
19
|
# Classify the files by DSL.
|
|
19
20
|
def move(dsl_path, from_paths, to_path)
|
|
20
|
-
classify(dsl_path, from_paths, to_path).each do |
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
classify(dsl_path, from_paths, to_path).each do |result|
|
|
22
|
+
if result.is_a? MoveFile
|
|
23
|
+
FileTools.move(result.from, result.to)
|
|
24
|
+
result.after_save_procs.each(&:call)
|
|
25
|
+
end
|
|
26
|
+
if result.is_a? RemoveFile
|
|
27
|
+
FileUtils.remove(result.from)
|
|
28
|
+
result.after_save_procs.each(&:call)
|
|
29
|
+
end
|
|
23
30
|
end
|
|
24
31
|
end
|
|
25
32
|
|
|
@@ -27,14 +34,17 @@ module Classifile
|
|
|
27
34
|
# Classify the files by DSL.
|
|
28
35
|
# However, the original file will remain.
|
|
29
36
|
def copy(dsl_path, from_paths, to_path)
|
|
30
|
-
classify(dsl_path, from_paths, to_path).each do |
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
classify(dsl_path, from_paths, to_path).each do |result|
|
|
38
|
+
if result.is_a? MoveFile
|
|
39
|
+
FileTools.move(result.from, result.to, copy: true)
|
|
40
|
+
result.after_save_procs.each(&:call)
|
|
41
|
+
end
|
|
42
|
+
result.after_save_procs.each(&:call) if result.is_a? RemoveFile
|
|
33
43
|
end
|
|
34
44
|
end
|
|
35
45
|
|
|
36
46
|
##
|
|
37
|
-
# Classify files by DSL and return an array of
|
|
47
|
+
# Classify files by DSL and return an array of MoveFile classes.
|
|
38
48
|
def classify(dsl_path, from_paths, to_path)
|
|
39
49
|
arr = []
|
|
40
50
|
dsl = FileTools.read_dsl(dsl_path)
|
data/lib/classifile/state.rb
CHANGED
|
@@ -33,21 +33,30 @@ module Classifile
|
|
|
33
33
|
return if @gotcha
|
|
34
34
|
|
|
35
35
|
child = make_child dir_name
|
|
36
|
-
child
|
|
36
|
+
child_run!(child, block) do
|
|
37
|
+
@gotcha = MoveFile.new(File.expand_path(@file.full_path),
|
|
38
|
+
File.expand_path(File.join(child.to_path, child.save_name)))
|
|
39
|
+
sets_after_save_proc(child)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else
|
|
41
|
-
raise Failed if dir_name.empty? || child.empty?
|
|
43
|
+
def group(_group_name = "", &block)
|
|
44
|
+
return if @gotcha
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
child = make_child ""
|
|
47
|
+
child_run!(child, block) do
|
|
48
|
+
# Ignored
|
|
44
49
|
end
|
|
45
|
-
rescue Failed
|
|
46
|
-
# Ignored
|
|
47
50
|
end
|
|
48
51
|
|
|
49
|
-
def
|
|
50
|
-
|
|
52
|
+
def del(&block)
|
|
53
|
+
return if @gotcha
|
|
54
|
+
|
|
55
|
+
child = make_child ""
|
|
56
|
+
child_run!(child, block) do
|
|
57
|
+
@gotcha = RemoveFile.new(File.expand_path(@file.full_path))
|
|
58
|
+
sets_after_save_proc(child)
|
|
59
|
+
end
|
|
51
60
|
end
|
|
52
61
|
|
|
53
62
|
def empty_dir!
|
|
@@ -60,9 +69,21 @@ module Classifile
|
|
|
60
69
|
|
|
61
70
|
private
|
|
62
71
|
|
|
63
|
-
def
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
def child_run!(child, proc)
|
|
73
|
+
child.instance_exec(@file, &proc)
|
|
74
|
+
|
|
75
|
+
if child.gotcha
|
|
76
|
+
@gotcha = child.gotcha
|
|
77
|
+
else
|
|
78
|
+
raise Failed if child.empty?
|
|
79
|
+
|
|
80
|
+
yield
|
|
81
|
+
end
|
|
82
|
+
rescue Failed
|
|
83
|
+
# Ignored
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def sets_after_save_proc(child)
|
|
66
87
|
child.after_save_syms.each do |sym|
|
|
67
88
|
@gotcha.after_save_procs << child.method(sym)
|
|
68
89
|
end
|
data/lib/classifile.rb
CHANGED
|
@@ -7,7 +7,9 @@ require_relative "classifile/checker/name_checker"
|
|
|
7
7
|
require_relative "classifile/checker/extension_checker"
|
|
8
8
|
require_relative "classifile/checker/assert_checker"
|
|
9
9
|
require_relative "classifile/io/file_tools"
|
|
10
|
-
require_relative "classifile/
|
|
10
|
+
require_relative "classifile/result/result"
|
|
11
|
+
require_relative "classifile/result/remove_file"
|
|
12
|
+
require_relative "classifile/result/move_file"
|
|
11
13
|
require_relative "classifile/classify"
|
|
12
14
|
require_relative "classifile/target_file"
|
|
13
15
|
require_relative "classifile/state"
|
data/sandbox/dsl/dsl.rb
CHANGED
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: classifile
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kurehajime
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-09-
|
|
11
|
+
date: 2021-09-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '1.7'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: simplecov
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.21'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.21'
|
|
55
69
|
description: classify file by ruby DSL.
|
|
56
70
|
email:
|
|
57
71
|
- xiidec@gmail.com
|
|
@@ -82,12 +96,15 @@ files:
|
|
|
82
96
|
- lib/classifile/const/version.rb
|
|
83
97
|
- lib/classifile/error/failed.rb
|
|
84
98
|
- lib/classifile/execute.rb
|
|
85
|
-
- lib/classifile/from_to.rb
|
|
86
99
|
- lib/classifile/io/file_tools.rb
|
|
100
|
+
- lib/classifile/result/move_file.rb
|
|
101
|
+
- lib/classifile/result/remove_file.rb
|
|
102
|
+
- lib/classifile/result/result.rb
|
|
87
103
|
- lib/classifile/state.rb
|
|
88
104
|
- lib/classifile/target_file.rb
|
|
89
105
|
- sandbox/dsl/dsl.rb
|
|
90
106
|
- sandbox/from/hello.md
|
|
107
|
+
- sandbox/from/remove.tmp
|
|
91
108
|
- sandbox/from/test.txt
|
|
92
109
|
- sandbox/from/xyz.txt
|
|
93
110
|
- sandbox/from/zzz.ini
|
data/lib/classifile/from_to.rb
DELETED