reenrb 0.1.1 → 0.2.1
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/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/bin/reen +1 -1
- data/lib/change.rb +29 -21
- data/lib/changes.rb +25 -2
- data/lib/reenrb/version.rb +1 -1
- data/lib/reenrb.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef0b76de4c05fb0949d2b65b6b7f79d3265fb1474e109de5186a788b1c32602c
|
4
|
+
data.tar.gz: 5c4a47408deed235d05236615380fdc35a099f4049d7fce833e3a06af48c2d96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe1b3c16fb10bdaa39c095acef4611822c2c07934081dfc1d223f2103d3cf07a3d819b50b5a1351cec1538d0fb24e03fd77d58eeef2bb212405a1c624b2f602
|
7
|
+
data.tar.gz: 88bd9ad15855e04911bd87b2d620843a254c31c0b84a4919c18cdaa314b8bd8c6953280450e8cefbbc32af1489e4c5034322bff26c4a63cdc2a9c57810b04348
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,7 +43,7 @@ Use programmatically using the `reenrb` gem. In the example below, we specify th
|
|
43
43
|
require 'reenrb'
|
44
44
|
|
45
45
|
glob = Dir.glob("*")
|
46
|
-
reen = Reenrb::Reen.new(
|
46
|
+
reen = Reenrb::Reen.new(editor: nil)
|
47
47
|
|
48
48
|
reen.execute(glob) do |tmpfile_path|
|
49
49
|
lines = File.read(tmpfile_path).split("\n")
|
@@ -55,6 +55,8 @@ reen.execute(glob) do |tmpfile_path|
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
You may also pass a block with an editor specified, in which case the block is run after the editor has finished.
|
59
|
+
|
58
60
|
## Development
|
59
61
|
|
60
62
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/bin/reen
CHANGED
data/lib/change.rb
CHANGED
@@ -40,22 +40,6 @@ module Reenrb
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def request_directory?
|
44
|
-
Dir.exist? @original
|
45
|
-
end
|
46
|
-
|
47
|
-
def request_delete?
|
48
|
-
@change == CHANGE::DELETE
|
49
|
-
end
|
50
|
-
|
51
|
-
def request_empty_directory?
|
52
|
-
Dir.empty? @original
|
53
|
-
end
|
54
|
-
|
55
|
-
def request_full_directory?
|
56
|
-
request_directory? && !request_empty_directory?
|
57
|
-
end
|
58
|
-
|
59
43
|
def consider
|
60
44
|
if request_full_directory? && request_delete?
|
61
45
|
@status = STATUS::REJECTED
|
@@ -65,12 +49,8 @@ module Reenrb
|
|
65
49
|
end
|
66
50
|
end
|
67
51
|
|
68
|
-
def executed_or_rejected
|
69
|
-
%i[executed rejected].include? @status
|
70
|
-
end
|
71
|
-
|
72
52
|
def execute
|
73
|
-
return(self) if executed_or_rejected
|
53
|
+
return(self) if executed_or_rejected?
|
74
54
|
|
75
55
|
case @change
|
76
56
|
when :rename
|
@@ -83,6 +63,34 @@ module Reenrb
|
|
83
63
|
self
|
84
64
|
end
|
85
65
|
|
66
|
+
# Inspection
|
67
|
+
|
68
|
+
def request_directory?
|
69
|
+
Dir.exist? @original
|
70
|
+
end
|
71
|
+
|
72
|
+
def request_delete?
|
73
|
+
@change == CHANGE::DELETE
|
74
|
+
end
|
75
|
+
|
76
|
+
def request_empty_directory?
|
77
|
+
Dir.empty? @original
|
78
|
+
end
|
79
|
+
|
80
|
+
def executed?
|
81
|
+
@status == STATUS::EXECUTED
|
82
|
+
end
|
83
|
+
|
84
|
+
def request_full_directory?
|
85
|
+
request_directory? && !request_empty_directory?
|
86
|
+
end
|
87
|
+
|
88
|
+
def executed_or_rejected?
|
89
|
+
%i[executed rejected].include? @status
|
90
|
+
end
|
91
|
+
|
92
|
+
# Decoration
|
93
|
+
|
86
94
|
def to_s
|
87
95
|
file_desc =
|
88
96
|
case @change
|
data/lib/changes.rb
CHANGED
@@ -9,10 +9,13 @@ module Reenrb
|
|
9
9
|
@list = changes_list
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def execute!
|
13
|
+
@list.map(&:execute)
|
14
|
+
self
|
14
15
|
end
|
15
16
|
|
17
|
+
# Inspection
|
18
|
+
|
16
19
|
def rename_requested
|
17
20
|
Changes.new(@list.select { |c| c.change == :rename })
|
18
21
|
end
|
@@ -37,10 +40,30 @@ module Reenrb
|
|
37
40
|
Changes.new(@list.select { |c| c.status == :executed })
|
38
41
|
end
|
39
42
|
|
43
|
+
def count
|
44
|
+
@list.size
|
45
|
+
end
|
46
|
+
|
47
|
+
# Decoration
|
48
|
+
|
40
49
|
def summarize
|
41
50
|
return "Nothing changed" if @list.empty?
|
42
51
|
|
43
52
|
@list.map(&:to_s).join("\n")
|
44
53
|
end
|
54
|
+
|
55
|
+
# Predicates
|
56
|
+
|
57
|
+
def no_changes_requested?
|
58
|
+
list.map(&:change).all? :none
|
59
|
+
end
|
60
|
+
|
61
|
+
def changes_requested?
|
62
|
+
!no_changes_requested?
|
63
|
+
end
|
64
|
+
|
65
|
+
def all_executed?
|
66
|
+
@list.all?(&:executed?)
|
67
|
+
end
|
45
68
|
end
|
46
69
|
end
|
data/lib/reenrb/version.rb
CHANGED
data/lib/reenrb.rb
CHANGED
@@ -9,8 +9,9 @@ module Reenrb
|
|
9
9
|
class Error < StandardError; end
|
10
10
|
|
11
11
|
# Renames pattern of files with given editor
|
12
|
-
#
|
12
|
+
# Examples:
|
13
13
|
# Reenrb::Reen.new(editor: "code -w").call("spec/fixtures/example/*")
|
14
|
+
# Reenrb::Reen.new(editor: nil).call("spec/fixtures/example/*") { ... }
|
14
15
|
class Reen
|
15
16
|
DEL_ERROR = "Do not delete any file/folder names"
|
16
17
|
|
@@ -21,20 +22,26 @@ module Reenrb
|
|
21
22
|
@options = options
|
22
23
|
end
|
23
24
|
|
24
|
-
def request(original_list, &block)
|
25
|
-
# original_list = Dir.glob(pattern)
|
25
|
+
def request(original_list, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
26
26
|
changed_list = ChangesFile.new(original_list).allow_changes do |file|
|
27
|
-
|
27
|
+
file.blocking_edit(@editor) if @editor
|
28
|
+
|
29
|
+
if block
|
30
|
+
lines = File.read(file.path).split("\n")
|
31
|
+
new_lines = block.call(lines) || lines
|
32
|
+
File.write(file.path, new_lines.join("\n"))
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
raise(Error, DEL_ERROR) if changed_list.size != original_list.size
|
31
37
|
|
32
38
|
@changes = compare_lists(original_list, changed_list)
|
39
|
+
.then { |change_array| Changes.new(change_array) }
|
33
40
|
end
|
34
41
|
|
35
42
|
def execute(original_list, &block)
|
36
43
|
@changes ||= request(original_list, &block)
|
37
|
-
@changes = @changes.
|
44
|
+
@changes = @changes.execute!
|
38
45
|
end
|
39
46
|
|
40
47
|
private
|