reenrb 0.3.2 → 0.4.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/README.md +49 -1
- data/lib/reenrb/actions/delete.rb +1 -1
- data/lib/reenrb/actions/force_delete.rb +20 -0
- data/lib/reenrb/actions/{file_rename.rb → rename.rb} +1 -1
- data/lib/reenrb/change.rb +46 -16
- data/lib/reenrb/changes_file.rb +1 -1
- data/lib/reenrb/version.rb +1 -1
- data/reenrb.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e28aaaf5fa1575c823af2027760cad2904c1d7e248ec79362dbd9c7f3762153
|
4
|
+
data.tar.gz: a300132794589824a89c9d17e75fd277537603b7ce7064a9ac341ba49ef423c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6aa3d99aa7b58e4c0c22fd109d33b9f5a57348fff6df8aff9874d97ea03125566a97b486b344fe6dcb9ad29d816b47f42c1603adfdad2cbd210a5fd1d183873
|
7
|
+
data.tar.gz: eae4c53636ff0f0146bbc79358b6044214a4e303f65f98aedc80fcd59cf1c37eb9d32ef71fd058936acff7e80a7e87bf525346a980aab55af296ffa05fd8e328
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Reen-rb is a utility written in Ruby (requires Ruby installed on your machine) that mass renames/deletes files by allowing the user to modify a list. It includes a command line executable called `reen` that opens the user's default editor to permit interactive changes, or can be used programatically by modifying the list of file names using a code block.
|
4
4
|
|
5
|
+
[](https://www.youtube.com/watch?v=yJfDRfJr3os)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
To install the command line utility, use:
|
@@ -38,9 +40,55 @@ Examples:
|
|
38
40
|
reen *.md --editor vi # reen all markdown files using vi
|
39
41
|
reen --editor 'code -w' # reen all markdown files using vscode
|
40
42
|
|
43
|
+
### Specifying changes through the editor
|
44
|
+
|
45
|
+
Upon running Reen on file list, your editor will open with a list of file/folder names. For example:
|
46
|
+
|
47
|
+
```
|
48
|
+
LICENSE.txt
|
49
|
+
README.md
|
50
|
+
SETUP.txt
|
51
|
+
bin
|
52
|
+
bin/help
|
53
|
+
bin/myexec
|
54
|
+
tests
|
55
|
+
tests/fixtures
|
56
|
+
tests/fixtures/a.json
|
57
|
+
tests/fixtures/b.json
|
58
|
+
tests/fixtures/c.json
|
59
|
+
tests/helper.code
|
60
|
+
tests/tests.code
|
61
|
+
```
|
62
|
+
|
63
|
+
Specify changes to each file you wish changed modifying it in your editor:
|
64
|
+
|
65
|
+
- Change the file/folder name to rename it (the rename could cause a move if you change its path; restrictions will be reported)
|
66
|
+
- Prepend using `-` to delete a file or empty folder
|
67
|
+
- Prepend using `--` to force delete a file or non-empty folder (recursively)
|
68
|
+
|
69
|
+
For example, if we wanted to change the above list of files/folders in the editor to (a) rename `LICENSE.txt` to `LICENSE.md`, (b) delete `SETUP.txt`, and (c) recursively delete the `bin/` folder, then we would change the filenames to look like:
|
70
|
+
|
71
|
+
```
|
72
|
+
LICENSE.md
|
73
|
+
README.md
|
74
|
+
-SETUP.txt
|
75
|
+
--bin
|
76
|
+
bin/help
|
77
|
+
bin/myexec
|
78
|
+
tests
|
79
|
+
tests/fixtures
|
80
|
+
tests/fixtures/a.json
|
81
|
+
tests/fixtures/b.json
|
82
|
+
tests/fixtures/c.json
|
83
|
+
tests/helper.code
|
84
|
+
tests/tests.code
|
85
|
+
```
|
86
|
+
|
87
|
+
Upon saving and exiting the editor, Reen will execute all the changes.
|
88
|
+
|
41
89
|
### Ruby application
|
42
90
|
|
43
|
-
Use programmatically using the `reenrb` gem. In the example below, we specify that we do not want to use an actual editor to modify the list, but rather alter the list file using a block.
|
91
|
+
Use Reen programmatically using the `reenrb` gem. In the example below, we specify that we do not want to use an actual editor to modify the list, but rather alter the list file using a block.
|
44
92
|
|
45
93
|
```ruby
|
46
94
|
require 'reenrb'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reenrb
|
4
|
+
module Actions
|
5
|
+
# Deletes a file
|
6
|
+
class ForceDelete
|
7
|
+
def initialize(old_name, new_name)
|
8
|
+
@old_name = old_name
|
9
|
+
@new_name = new_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
FileUtils.rm_rf(@old_name)
|
14
|
+
nil
|
15
|
+
rescue Errno::ENOENT
|
16
|
+
"Could not force delete"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/reenrb/change.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "actions/delete"
|
4
|
-
require_relative "actions/
|
4
|
+
require_relative "actions/force_delete"
|
5
|
+
require_relative "actions/rename"
|
5
6
|
require_relative "actions/nothing"
|
6
7
|
|
7
8
|
module Reenrb
|
@@ -19,44 +20,71 @@ module Reenrb
|
|
19
20
|
module CHANGE
|
20
21
|
NONE = :none
|
21
22
|
DELETE = :delete
|
23
|
+
FORCE_DELETE = :force_delete
|
22
24
|
RENAME = :rename
|
23
25
|
end
|
24
26
|
|
27
|
+
module OBJECT
|
28
|
+
FILE = :file
|
29
|
+
FOLDER = :folder
|
30
|
+
end
|
31
|
+
|
25
32
|
ACTION_HANDLER = {
|
26
33
|
CHANGE::NONE => Actions::DoNothing,
|
27
|
-
CHANGE::DELETE => Actions::
|
28
|
-
CHANGE::
|
34
|
+
CHANGE::DELETE => Actions::Delete,
|
35
|
+
CHANGE::FORCE_DELETE => Actions::ForceDelete,
|
36
|
+
CHANGE::RENAME => Actions::Rename
|
29
37
|
}.freeze
|
30
38
|
|
31
39
|
CHANGES_DESC = {
|
32
40
|
CHANGE::NONE => "Nothing",
|
33
41
|
CHANGE::DELETE => "Deleting",
|
42
|
+
CHANGE::FORCE_DELETE => "Force deleting",
|
34
43
|
CHANGE::RENAME => "Renaming"
|
35
44
|
}.freeze
|
36
45
|
|
37
46
|
def initialize(original, requested)
|
38
47
|
@original = original
|
39
|
-
|
40
|
-
|
41
|
-
|
48
|
+
extract_request(requested)
|
49
|
+
decide_object
|
50
|
+
decide_change
|
51
|
+
decide_status_reason
|
42
52
|
end
|
43
53
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
def extract_request(str)
|
55
|
+
op_chars = "[-]"
|
56
|
+
obj_chars = "."
|
57
|
+
requested = str.match(/^(?<op>#{op_chars}*)(?<name>#{obj_chars}*)/)
|
58
|
+
|
59
|
+
@operator = requested[:op]
|
60
|
+
@requested = requested[:name].strip
|
61
|
+
end
|
62
|
+
|
63
|
+
def decide_change
|
64
|
+
@change =
|
65
|
+
if @operator == "--"
|
66
|
+
CHANGE::FORCE_DELETE
|
67
|
+
elsif @operator == "-"
|
68
|
+
CHANGE::DELETE
|
69
|
+
elsif @original != @requested
|
70
|
+
CHANGE::RENAME
|
71
|
+
else
|
72
|
+
CHANGE::NONE
|
73
|
+
end
|
52
74
|
end
|
53
75
|
|
54
|
-
def
|
76
|
+
def decide_object
|
77
|
+
@object = OBJECT::FILE if request_file?
|
78
|
+
@object = OBJECT::FOLDER if request_dir?
|
79
|
+
end
|
80
|
+
|
81
|
+
def decide_status_reason
|
55
82
|
if request_full_dir? && request_delete?
|
56
83
|
@status = STATUS::REJECTED
|
57
84
|
@reason = "Directories with files cannot be changed"
|
58
85
|
else
|
59
86
|
@status = STATUS::ACCEPTED
|
87
|
+
@reason = ""
|
60
88
|
end
|
61
89
|
end
|
62
90
|
|
@@ -64,7 +92,7 @@ module Reenrb
|
|
64
92
|
return(self) if not_accepted?
|
65
93
|
|
66
94
|
@status = STATUS::EXECUTED
|
67
|
-
error = ACTION_HANDLER[@change].new(original, requested).call
|
95
|
+
error = ACTION_HANDLER[@change].new(@original, @requested).call
|
68
96
|
|
69
97
|
if error
|
70
98
|
@status = STATUS::FAILED
|
@@ -78,6 +106,8 @@ module Reenrb
|
|
78
106
|
|
79
107
|
def request_dir? = Dir.exist?(@original)
|
80
108
|
|
109
|
+
def request_file? = File.file?(@original)
|
110
|
+
|
81
111
|
def request_nothing? = @change == CHANGE::NONE
|
82
112
|
|
83
113
|
def request_rename? = @change == CHANGE::RENAME
|
data/lib/reenrb/changes_file.rb
CHANGED
data/lib/reenrb/version.rb
CHANGED
data/reenrb.gemspec
CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency "rerun", "~> 0.13"
|
37
37
|
spec.add_development_dependency "rubocop", "~> 1.21"
|
38
38
|
spec.add_development_dependency "rubyzip", "~> 2.3"
|
39
|
+
spec.add_development_dependency "simplecov"
|
39
40
|
|
40
41
|
# For more information and examples about making a new gem, check out our
|
41
42
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reenrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soumya Ray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Renames or deletes a pattern of files using your favorite editor
|
98
112
|
email:
|
99
113
|
- soumya.ray@gmail.com
|
@@ -111,8 +125,9 @@ files:
|
|
111
125
|
- bin/reen
|
112
126
|
- lib/reenrb.rb
|
113
127
|
- lib/reenrb/actions/delete.rb
|
114
|
-
- lib/reenrb/actions/
|
128
|
+
- lib/reenrb/actions/force_delete.rb
|
115
129
|
- lib/reenrb/actions/nothing.rb
|
130
|
+
- lib/reenrb/actions/rename.rb
|
116
131
|
- lib/reenrb/change.rb
|
117
132
|
- lib/reenrb/changes.rb
|
118
133
|
- lib/reenrb/changes_file.rb
|