git-gsub-ruby 0.1.1 → 1.0.2

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: d33a842934c9b3979fac8b0abb80548316a3a41b54884dfbca05d24684eed208
4
+ data.tar.gz: 11461fb6325472b2f39add42a9552029dafc0f31c0825faf867fef80983fd51f
5
5
  SHA512:
6
- metadata.gz: 209ebe092abb70d0bbcdc5b244765f3d35828755449c92092ecaca6cb1b5a1b314c0109f6cca155166b94d74575a2fdeaf56f6c20d9fb41914192633553dcf8c
7
- data.tar.gz: 801df11de6bb1dcac22c6ab94ddbbbe9b90106c39a3dda9393a8cea08e95f4a8a72061fbb406994d07bfdf4a44067f9ab0fc5145f35e02a88e4174605ba342a8
6
+ metadata.gz: 31b8b4027ba0091248cc6d1290c278d5b6c18a1b2989f27887325ce4fcb2080a621c91debe4726bbc4fa7850f9db0c0334aaf352e0c154a34c1d3ec0eaff706b
7
+ data.tar.gz: e7c68dc73aa94ad3fc3a4e9a2dfbe4f4e16aeddfef7f8a19ced4e4761da2e3dd4481d3ddd6cb97c9f8d523a1debc909409abf636cc0fc24a54f12b4edaac80e5
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.1.2
data/exe/git-gsub-ruby CHANGED
@@ -10,36 +10,42 @@ def text_file?(filename)
10
10
  status.success? && file_type.include?("text")
11
11
  end
12
12
 
13
- ARGV.extend OptionParser::Arguable
14
- ARGV.options.version = Git::Gsub::Ruby::VERSION
15
- ARGV.options.banner = <<USAGE
13
+ evaluate = false
14
+ debug = false
15
+
16
+ opts = OptionParser.new do |o|
17
+ o.version = Git::Gsub::Ruby::VERSION
18
+ o.banner = <<-USAGE
16
19
  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`.
20
+ ruby #{File.basename(__FILE__)} [options] from to [glob]
21
+ from - gsub from string or ruby script
22
+ to - gsub to string or ruby script
23
+ glob - (optional)ruby glob pattern.
23
24
 
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
25
+ Example:
26
+ git gsub hoge piyo
27
+ git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
28
+ 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'
29
+ Options:
30
+ USAGE
31
+ o.on('-e', '--eval', 'Evaluate `from` and `to` as a ruby script and replace the `to` string with the result of `from`.') { evaluate = true }
32
+ o.on('-d', '--debug', 'Print debug.') { debug = true }
33
+ end
29
34
 
30
- opts = ARGV.getopts('e', 'eval')
31
- evaluate = (opts['e'] || opts['eval']) ? true : false
35
+ opts.parse!(ARGV)
32
36
 
33
37
  begin
34
38
  raise "Invalid argument" if ARGV.size != 2 && ARGV.size != 3
35
39
 
36
- from_str, to_str, glob = ARGV
40
+ from_str, to_str, glob_pattern = ARGV
37
41
  from = evaluate ? eval(from_str) : from_str
38
- glob ||= '**/*'
39
- puts "from: #{from.inspect}, to_str: #{to_str}, glob: #{glob}"
42
+ glob_pattern ||= '**/*'
43
+ puts "from: #{from.inspect}, to_str: #{to_str}, glob: #{glob_pattern}" if debug
44
+ glob = Pathname.glob(glob_pattern, File::FNM_DOTMATCH)
40
45
 
41
46
  lsfiles = `git ls-files`
42
- files = lsfiles.lines.to_a.map { |path| Pathname.new(path.strip) } & Pathname.glob(glob)
47
+ files = lsfiles.lines.to_a.map { |path| Pathname.new(path.strip) } & glob
48
+
43
49
  files.each do |path|
44
50
  next unless text_file? path
45
51
  buf = nil
@@ -58,7 +64,7 @@ begin
58
64
  end
59
65
  end
60
66
  if buf
61
- puts "replaced:#{path}"
67
+ puts "replaced:#{path}" if debug
62
68
  open(path, "w") do |f|
63
69
  f.write buf
64
70
  end
@@ -66,6 +72,8 @@ begin
66
72
  end
67
73
  rescue => ex
68
74
  puts ex.message
69
- puts ex.backtrace
70
- puts ARGV.options.help
75
+ if debug
76
+ puts ex.backtrace
77
+ end
78
+ puts opts.help
71
79
  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.2"
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.2
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: 2022-11-05 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.3.7
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