reenrb 0.3.3 → 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 +47 -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/version.rb +1 -1
- metadata +4 -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
@@ -40,9 +40,55 @@ Examples:
|
|
40
40
|
reen *.md --editor vi # reen all markdown files using vi
|
41
41
|
reen --editor 'code -w' # reen all markdown files using vscode
|
42
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
|
+
|
43
89
|
### Ruby application
|
44
90
|
|
45
|
-
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.
|
46
92
|
|
47
93
|
```ruby
|
48
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/version.rb
CHANGED
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
|
@@ -125,8 +125,9 @@ files:
|
|
125
125
|
- bin/reen
|
126
126
|
- lib/reenrb.rb
|
127
127
|
- lib/reenrb/actions/delete.rb
|
128
|
-
- lib/reenrb/actions/
|
128
|
+
- lib/reenrb/actions/force_delete.rb
|
129
129
|
- lib/reenrb/actions/nothing.rb
|
130
|
+
- lib/reenrb/actions/rename.rb
|
130
131
|
- lib/reenrb/change.rb
|
131
132
|
- lib/reenrb/changes.rb
|
132
133
|
- lib/reenrb/changes_file.rb
|