rubyn 0.1.2 → 0.1.4
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16ab57a500ce5c84a9b0b365492f000f5abb7e2e7e692b111aea9af8d003a811
|
|
4
|
+
data.tar.gz: 623e6e54abcd15c518a51185360dd1dc15aac752d744071590f55dfc8579f103
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12b03663f2ec51a1d750e42fa378ddc544f1e4e0548686921df2e9680aea698313fbe5de8e117fe22f58d3feeb68e0b7a8b2d468c8026bf6477f1a36ee5c2810
|
|
7
|
+
data.tar.gz: '00826e6c27136e1d50638008975c9afaf942458885e1587c8b627df0e6b0f04a3e0a9d9185d1de31a6a054d523ffb92847a15c279ac0edbd6a406c6fe092fab0'
|
|
@@ -18,14 +18,6 @@ module Rubyn
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def new_file?(path)
|
|
22
|
-
return false unless path
|
|
23
|
-
|
|
24
|
-
path != @original_file &&
|
|
25
|
-
!path.end_with?("/#{@original_file}") &&
|
|
26
|
-
!@original_file.end_with?("/#{path}")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
21
|
private
|
|
30
22
|
|
|
31
23
|
def apply_single(code)
|
|
@@ -50,7 +42,7 @@ module Rubyn
|
|
|
50
42
|
@formatter.info("This refactor produces #{file_blocks.length} file(s):")
|
|
51
43
|
file_blocks.each do |block|
|
|
52
44
|
path = block[:path] || @original_file
|
|
53
|
-
label =
|
|
45
|
+
label = block[:tag] == "new" ? "NEW" : "MODIFIED"
|
|
54
46
|
@formatter.info(" [#{label}] #{path}")
|
|
55
47
|
end
|
|
56
48
|
|
|
@@ -69,7 +61,7 @@ module Rubyn
|
|
|
69
61
|
|
|
70
62
|
def apply_selected(block)
|
|
71
63
|
path = block[:path] || @original_file
|
|
72
|
-
label =
|
|
64
|
+
label = block[:tag] == "new" ? "NEW" : "MODIFIED"
|
|
73
65
|
print " Apply [#{label}] #{path}? (y/n/diff) "
|
|
74
66
|
choice = $stdin.gets&.strip&.downcase
|
|
75
67
|
|
|
@@ -77,7 +69,7 @@ module Rubyn
|
|
|
77
69
|
when "y"
|
|
78
70
|
write_block(block)
|
|
79
71
|
when "diff"
|
|
80
|
-
existing =
|
|
72
|
+
existing = block[:tag] == "new" ? "" : File.read(resolve_path(block))
|
|
81
73
|
Rubyn::Output::DiffRenderer.render(original: existing, modified: block[:code])
|
|
82
74
|
print " Apply? (y/n) "
|
|
83
75
|
write_block(block) if $stdin.gets&.strip&.downcase == "y"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Rubyn
|
|
4
4
|
module Context
|
|
5
5
|
class ResponseParser
|
|
6
|
-
BOLD_HEADER = /\*\*(
|
|
6
|
+
BOLD_HEADER = /\*\*(New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i
|
|
7
7
|
BACKTICK_PATH = /`([a-zA-Z0-9_\/\.\-]+\.rb)`\s*\z/
|
|
8
8
|
INLINE_COMMENT = /^#\s*([a-zA-Z0-9_\/\.\-]+\.rb)/
|
|
9
9
|
|
|
@@ -24,9 +24,9 @@ module Rubyn
|
|
|
24
24
|
|
|
25
25
|
code = part.sub(/\A```ruby\n/, "").sub(/```\z/, "")
|
|
26
26
|
preceding = i > 0 ? parts[i - 1] : ""
|
|
27
|
-
|
|
27
|
+
result = detect_path(preceding, code)
|
|
28
28
|
|
|
29
|
-
blocks << { path: path, code: code }
|
|
29
|
+
blocks << { path: result[:path], tag: result[:tag], code: code }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
blocks
|
|
@@ -37,19 +37,29 @@ module Rubyn
|
|
|
37
37
|
def detect_path(preceding_text, code)
|
|
38
38
|
match_bold_header(preceding_text) ||
|
|
39
39
|
match_backtick_path(preceding_text) ||
|
|
40
|
-
match_inline_comment(code)
|
|
40
|
+
match_inline_comment(code) ||
|
|
41
|
+
{ path: nil, tag: nil }
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def match_bold_header(text)
|
|
44
|
-
text.match(BOLD_HEADER)
|
|
45
|
+
m = text.match(BOLD_HEADER)
|
|
46
|
+
return nil unless m
|
|
47
|
+
|
|
48
|
+
{ path: m[2], tag: m[1].downcase }
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
def match_backtick_path(text)
|
|
48
|
-
text.match(BACKTICK_PATH)
|
|
52
|
+
m = text.match(BACKTICK_PATH)
|
|
53
|
+
return nil unless m
|
|
54
|
+
|
|
55
|
+
{ path: m[1], tag: nil }
|
|
49
56
|
end
|
|
50
57
|
|
|
51
58
|
def match_inline_comment(code)
|
|
52
|
-
code.lines.first&.strip&.match(INLINE_COMMENT)
|
|
59
|
+
m = code.lines.first&.strip&.match(INLINE_COMMENT)
|
|
60
|
+
return nil unless m
|
|
61
|
+
|
|
62
|
+
{ path: m[1], tag: nil }
|
|
53
63
|
end
|
|
54
64
|
end
|
|
55
65
|
end
|
|
@@ -297,7 +297,7 @@
|
|
|
297
297
|
var fileChanges = codeBlocks.map(function(code, i) {
|
|
298
298
|
var header = fileHeaders[i];
|
|
299
299
|
var path = (header && header.path) ? header.path : file;
|
|
300
|
-
var isNew =
|
|
300
|
+
var isNew = header && header.tag === "new";
|
|
301
301
|
return {
|
|
302
302
|
path: path,
|
|
303
303
|
isNew: isNew,
|
|
@@ -488,10 +488,12 @@
|
|
|
488
488
|
var code = parts[i].replace(/^```ruby\n/, "").replace(/```$/, "");
|
|
489
489
|
var preceding = i > 0 ? parts[i - 1] : "";
|
|
490
490
|
var path = null;
|
|
491
|
+
var tag = null;
|
|
491
492
|
|
|
492
|
-
// Strategy 1: Bold header (**New file: path.rb**, **Updated file: path.rb
|
|
493
|
-
|
|
494
|
-
|
|
493
|
+
// Strategy 1: Bold header (**New file: path.rb**, **Updated file: path.rb**)
|
|
494
|
+
// Only match when preceded by New/Updated/Modified to avoid matching bold .rb references in prose
|
|
495
|
+
var boldMatch = preceding.match(/\*\*(New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i);
|
|
496
|
+
if (boldMatch) { tag = boldMatch[1].toLowerCase(); path = boldMatch[2]; }
|
|
495
497
|
|
|
496
498
|
// Strategy 3: Backtick-wrapped path above code block
|
|
497
499
|
if (!path) {
|
|
@@ -506,7 +508,7 @@
|
|
|
506
508
|
if (commentMatch) path = commentMatch[1];
|
|
507
509
|
}
|
|
508
510
|
|
|
509
|
-
headers.push({ path: path });
|
|
511
|
+
headers.push({ path: path, tag: tag });
|
|
510
512
|
}
|
|
511
513
|
|
|
512
514
|
return headers;
|
data/lib/rubyn/version.rb
CHANGED