geny 2.1.0 → 2.1.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/lib/geny/actions/find.rb +45 -34
- data/lib/geny/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 558b6cc3a2985012f76f27a23c8a1a338aef4bdf
|
4
|
+
data.tar.gz: a859475b06d94fdba962beb25b0ffece71eb1119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd59935ac74a3cdb86e94e93c61e2154a5a62db930c0f699aef8ff5d9d825d2dc78da99e2a5e94cd103c410b12ac5aac9aac1ff480d2ff5ab4f2ba79b546d9dc
|
7
|
+
data.tar.gz: 0c4465488a3d5920d51659e399cbed3d972179ea7d528c79e9ab92e4f3fffca154565858e78b2f99c674fbf5cd72696ecf2970b6b9ae1dc4c8a8fc803f965f19
|
data/lib/geny/actions/find.rb
CHANGED
@@ -4,6 +4,7 @@ require "tty-file"
|
|
4
4
|
|
5
5
|
module Geny
|
6
6
|
module Actions
|
7
|
+
# Utilities for manipulating files in bulk
|
7
8
|
class Find
|
8
9
|
# Replace the content of any file that matches the pattern with
|
9
10
|
# a replacement
|
@@ -17,21 +18,27 @@ module Geny
|
|
17
18
|
# @example
|
18
19
|
# find.replace("src", "Boilerplate", "YourProject")
|
19
20
|
def replace(root, pattern, replacement, force: false, excluding: nil)
|
20
|
-
::Find.find(root)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
::Find.find(root) do |path|
|
22
|
+
# The first emitted path will be the root directory
|
23
|
+
next if path == root
|
24
|
+
|
25
|
+
# Don't look any further into this directory
|
26
|
+
::Find.prune if excluding && excluding.match?(excluding)
|
27
|
+
|
28
|
+
# We don't care about directories
|
29
|
+
next if File.directory?(path)
|
30
|
+
|
31
|
+
# We can't replace binary files
|
32
|
+
next if TTY::File.binary?(path)
|
33
|
+
|
34
|
+
TTY::File.replace_in_file(
|
35
|
+
path,
|
36
|
+
pattern,
|
37
|
+
replacement,
|
38
|
+
verbose: false,
|
39
|
+
force: force
|
40
|
+
)
|
41
|
+
end
|
35
42
|
end
|
36
43
|
|
37
44
|
# Replace any filename that matches the pattern with a replacement
|
@@ -44,28 +51,32 @@ module Geny
|
|
44
51
|
# @example
|
45
52
|
# find.rename("src", "Boilerplate", "YourProject")
|
46
53
|
def rename(root, pattern, replacement, force: false, excluding: nil)
|
47
|
-
|
48
|
-
|
49
|
-
.reject { |path| path == root }
|
50
|
-
.reject { |path| excluding && path.match?(excluding) }
|
51
|
-
.select { |path| path.match?(pattern) }
|
52
|
-
.sort { |path| depth(path) }
|
53
|
-
.map { |path| [path, rsub(path, pattern, replacement)] }
|
54
|
-
.each { |source, dest| FileUtils.mv(source, dest) }
|
55
|
-
end
|
54
|
+
matches = []
|
55
|
+
options = {force: force, excluding: nil}
|
56
56
|
|
57
|
-
|
57
|
+
::Find.find(root) do |path|
|
58
|
+
# The first emitted path will be the root directory
|
59
|
+
next if path == root
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
# Don't look any further into this directory
|
62
|
+
::Find.prune if excluding && excluding.match?(excluding)
|
63
|
+
|
64
|
+
# The path doesn't match, keep searching
|
65
|
+
next unless path.match?(pattern)
|
66
|
+
|
67
|
+
# Record the match
|
68
|
+
matches << path
|
69
|
+
|
70
|
+
# Don't search the children of the match, because it will
|
71
|
+
# be renamed. We'll have re-run against the renamed path
|
72
|
+
::Find.prune
|
73
|
+
end
|
65
74
|
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
matches.each do |source|
|
76
|
+
dest = source.sub(pattern, replacement)
|
77
|
+
FileUtils.mv(source, dest, force: force)
|
78
|
+
rename(dest, pattern, replacement, options) if File.directory?(dest)
|
79
|
+
end
|
69
80
|
end
|
70
81
|
end
|
71
82
|
end
|
data/lib/geny/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Zane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: argy
|