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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7570c41ec58d0733f1fa5a2af3ca3bb14b6aea8bff9a0b44a58c58bccff3162
4
- data.tar.gz: 0ffd19adbfbb24c0e188662af90a252495f063ab37d9a6cefa4309f97639c4ed
3
+ metadata.gz: 6c628fabb081f67c8fe9de3459511965e921624c092258bf06f2d2d53df41240
4
+ data.tar.gz: 62f26dcc5d396d2c6e6bace90eaf3b07bf876acb25022cdb4cb416aaa8ffcc7f
5
5
  SHA512:
6
- metadata.gz: 209ebe092abb70d0bbcdc5b244765f3d35828755449c92092ecaca6cb1b5a1b314c0109f6cca155166b94d74575a2fdeaf56f6c20d9fb41914192633553dcf8c
7
- data.tar.gz: 801df11de6bb1dcac22c6ab94ddbbbe9b90106c39a3dda9393a8cea08e95f4a8a72061fbb406994d07bfdf4a44067f9ab0fc5145f35e02a88e4174605ba342a8
6
+ metadata.gz: b1ed01b1a67a4a2c3ff3a01a723d0ebb96fe781acf69e848c7a7a4cec4e19315d3ee959755a59f68719b6545d7f8a79c2362e3d3a4dd44d84f7e23645fe2eb3d
7
+ data.tar.gz: 75c22eff73a3db72ed77d51d86273e59afbc6a75eb7d0d303e95ee593e9dbdac84183ca290b0dbd0f3b85cfeb770f61e956579122cab2b0ad762a600ac878b21
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ Gemfile.lock
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
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
- def text_file?(filename)
9
- file_type, status = Open3.capture2e("file", filename.to_s)
10
- status.success? && file_type.include?("text")
11
- end
8
+ evaluate = false
9
+ debug = false
12
10
 
13
- ARGV.extend OptionParser::Arguable
14
- ARGV.options.version = Git::Gsub::Ruby::VERSION
15
- ARGV.options.banner = <<USAGE
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
- example:
25
- git gsub hoge piyo
26
- git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
27
- 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'
28
- USAGE
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 = ARGV.getopts('e', 'eval')
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, glob = ARGV
35
+ from_str, to_str, glob_pattern = ARGV
37
36
  from = evaluate ? eval(from_str) : from_str
38
- glob ||= '**/*'
39
- puts "from: #{from.inspect}, to_str: #{to_str}, glob: #{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) } & Pathname.glob(glob)
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
- puts ex.backtrace
70
- puts ARGV.options.help
71
+ if debug
72
+ puts ex.backtrace
73
+ end
74
+ puts opts.help
71
75
  end
@@ -1,7 +1,7 @@
1
1
  module Git
2
2
  module Gsub
3
3
  module Ruby
4
- VERSION = "0.1.1"
4
+ VERSION = "1.0.3"
5
5
  end
6
6
  end
7
7
  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.1.1
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: 2020-08-30 00:00:00.000000000 Z
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.1.2
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