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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: feea0d19f57dac06caefb00e6350c462c4730dcbbda1fa35085e89ae3e7d1d16
4
- data.tar.gz: ca06bec8bbbd2e3d483eea48f7626b38094f3c9c922c25a6b4d0be2b0e7fd003
3
+ metadata.gz: 7e28aaaf5fa1575c823af2027760cad2904c1d7e248ec79362dbd9c7f3762153
4
+ data.tar.gz: a300132794589824a89c9d17e75fd277537603b7ce7064a9ac341ba49ef423c7
5
5
  SHA512:
6
- metadata.gz: c2251f9c77d2f30bdb450d61749d402d1264a24c56aabaf05d14dbe3e5e061e5e3425ac603b6fe3104224b303d6bbb1dc260d3853d4e380b765d5639fe3cfedf
7
- data.tar.gz: 001fee56fd50a98c6cfda7bcc8bf551cd446ec6417584f0f6ea8a5e95c0b2c764dfc88a55f13dcc4ea5ffd71ef4f09f5611a183436b64827a111fa0431aa7375
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'
@@ -3,7 +3,7 @@
3
3
  module Reenrb
4
4
  module Actions
5
5
  # Deletes a file
6
- class FileDelete
6
+ class Delete
7
7
  def initialize(old_name, new_name)
8
8
  @old_name = old_name
9
9
  @new_name = new_name
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Reenrb
4
4
  module Actions
5
5
  # Renames files
6
- class FileRename
6
+ class Rename
7
7
  def initialize(old_name, new_name)
8
8
  @old_name = old_name
9
9
  @new_name = new_name
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/file_rename"
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::FileDelete,
28
- CHANGE::RENAME => Actions::FileRename
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
- @requested = requested
40
- @change = compare
41
- consider
48
+ extract_request(requested)
49
+ decide_object
50
+ decide_change
51
+ decide_status_reason
42
52
  end
43
53
 
44
- def compare
45
- if original == requested
46
- CHANGE::NONE
47
- elsif requested.start_with? "-"
48
- CHANGE::DELETE
49
- else
50
- CHANGE::RENAME
51
- end
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 consider
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reenrb
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.3
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-28 00:00:00.000000000 Z
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/file_rename.rb
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