git-gsub-ruby 0.1.1 → 1.0.3
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/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/exe/git-gsub-ruby +33 -29
- data/lib/git/gsub/ruby/version.rb +1 -1
- metadata +3 -4
- data/Gemfile.lock +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c628fabb081f67c8fe9de3459511965e921624c092258bf06f2d2d53df41240
|
4
|
+
data.tar.gz: 62f26dcc5d396d2c6e6bace90eaf3b07bf876acb25022cdb4cb416aaa8ffcc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1ed01b1a67a4a2c3ff3a01a723d0ebb96fe781acf69e848c7a7a4cec4e19315d3ee959755a59f68719b6545d7f8a79c2362e3d3a4dd44d84f7e23645fe2eb3d
|
7
|
+
data.tar.gz: 75c22eff73a3db72ed77d51d86273e59afbc6a75eb7d0d303e95ee593e9dbdac84183ca290b0dbd0f3b85cfeb770f61e956579122cab2b0ad762a600ac878b21
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.2
|
data/exe/git-gsub-ruby
CHANGED
@@ -5,46 +5,48 @@ require 'optparse'
|
|
5
5
|
require 'git/gsub/ruby'
|
6
6
|
require 'pathname'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
status.success? && file_type.include?("text")
|
11
|
-
end
|
8
|
+
evaluate = false
|
9
|
+
debug = false
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
opts = OptionParser.new do |o|
|
12
|
+
o.version = Git::Gsub::Ruby::VERSION
|
13
|
+
o.banner = <<-USAGE
|
16
14
|
Usage:
|
17
|
-
ruby #{File.basename(__FILE__)} [options] from to [glob]
|
18
|
-
from - gsub from string or ruby script
|
19
|
-
to - gsub to string or ruby script
|
20
|
-
glob - (optional)ruby glob pattern.
|
21
|
-
options:
|
22
|
-
-e|--eval Evaluate `from` and `to` as a ruby script and replace the `to` string with the result of `from`.
|
15
|
+
ruby #{File.basename(__FILE__)} [options] from to [glob]
|
16
|
+
from - gsub from string or ruby script
|
17
|
+
to - gsub to string or ruby script
|
18
|
+
glob - (optional)ruby glob pattern.
|
23
19
|
|
24
|
-
|
25
|
-
git gsub hoge piyo
|
26
|
-
git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
|
27
|
-
git gsub -e '/belongs_to :(\w+)([
|
28
|
-
|
20
|
+
Example:
|
21
|
+
git gsub hoge piyo
|
22
|
+
git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
|
23
|
+
git gsub -e '/belongs_to :(\w+)([^#\\n]*)(#.*)?$/' '"belongs_to :\#{$1}\#{$2.include?("optional: false") ? $2 : $2.strip + ", optional: true"}\#{$3 != nil ? " " + $3 : ""}"' 'app/models/**/*.rb'
|
24
|
+
Options:
|
25
|
+
USAGE
|
26
|
+
o.on('-e', '--eval', 'Evaluate `from` and `to` as a ruby script and replace the `to` string with the result of `from`.') { evaluate = true }
|
27
|
+
o.on('-d', '--debug', 'Print debug.') { debug = true }
|
28
|
+
end
|
29
29
|
|
30
|
-
opts
|
31
|
-
evaluate = (opts['e'] || opts['eval']) ? true : false
|
30
|
+
opts.parse!(ARGV)
|
32
31
|
|
33
32
|
begin
|
34
33
|
raise "Invalid argument" if ARGV.size != 2 && ARGV.size != 3
|
35
34
|
|
36
|
-
from_str, to_str,
|
35
|
+
from_str, to_str, glob_pattern = ARGV
|
37
36
|
from = evaluate ? eval(from_str) : from_str
|
38
|
-
|
39
|
-
puts "from: #{from.inspect}, to_str: #{to_str}, glob: #{
|
37
|
+
glob_pattern ||= '**/*'
|
38
|
+
puts "from: #{from.inspect}, to_str: #{to_str}, glob: #{glob_pattern}" if debug
|
39
|
+
glob = Pathname.glob(glob_pattern, File::FNM_DOTMATCH)
|
40
40
|
|
41
41
|
lsfiles = `git ls-files`
|
42
|
-
files = lsfiles.lines.to_a.map { |path| Pathname.new(path.strip) } &
|
42
|
+
files = lsfiles.lines.to_a.map { |path| Pathname.new(path.strip) } & glob
|
43
|
+
|
43
44
|
files.each do |path|
|
44
|
-
next unless text_file? path
|
45
45
|
buf = nil
|
46
|
-
open(path) do |f|
|
46
|
+
open(path, 'rb') do |f|
|
47
47
|
old_buf = f.read
|
48
|
+
next unless old_buf.valid_encoding?
|
49
|
+
|
48
50
|
begin
|
49
51
|
if evaluate
|
50
52
|
buf = old_buf.gsub(from) { eval(to_str) }
|
@@ -58,7 +60,7 @@ begin
|
|
58
60
|
end
|
59
61
|
end
|
60
62
|
if buf
|
61
|
-
puts "replaced:#{path}"
|
63
|
+
puts "replaced:#{path}" if debug
|
62
64
|
open(path, "w") do |f|
|
63
65
|
f.write buf
|
64
66
|
end
|
@@ -66,6 +68,8 @@ begin
|
|
66
68
|
end
|
67
69
|
rescue => ex
|
68
70
|
puts ex.message
|
69
|
-
|
70
|
-
|
71
|
+
if debug
|
72
|
+
puts ex.backtrace
|
73
|
+
end
|
74
|
+
puts opts.help
|
71
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-gsub-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsusuke Shimizu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: You can control the gsub replacement with the ruby script.
|
14
14
|
email:
|
@@ -24,7 +24,6 @@ files:
|
|
24
24
|
- ".travis.yml"
|
25
25
|
- CODE_OF_CONDUCT.md
|
26
26
|
- Gemfile
|
27
|
-
- Gemfile.lock
|
28
27
|
- LICENSE
|
29
28
|
- LICENSE.txt
|
30
29
|
- README.md
|
@@ -58,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
57
|
- !ruby/object:Gem::Version
|
59
58
|
version: '0'
|
60
59
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.4.10
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: Replace text for all git controlled files by ruby gsub.
|
data/Gemfile.lock
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
git-gsub-ruby (0.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.4.4)
|
10
|
-
rake (12.3.3)
|
11
|
-
rspec (3.9.0)
|
12
|
-
rspec-core (~> 3.9.0)
|
13
|
-
rspec-expectations (~> 3.9.0)
|
14
|
-
rspec-mocks (~> 3.9.0)
|
15
|
-
rspec-core (3.9.2)
|
16
|
-
rspec-support (~> 3.9.3)
|
17
|
-
rspec-expectations (3.9.2)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.9.0)
|
20
|
-
rspec-mocks (3.9.1)
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.9.0)
|
23
|
-
rspec-support (3.9.3)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
git-gsub-ruby!
|
30
|
-
rake (~> 12.0)
|
31
|
-
rspec (~> 3.0)
|
32
|
-
|
33
|
-
BUNDLED WITH
|
34
|
-
2.1.4
|