git-gsub-ruby 0.1.0 → 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: e778d25da67553400aa27cd4b1592229a20daf2251cdf65b92e0c0d382f24aa7
4
- data.tar.gz: 96e15dffe75875c82b08f15fd8212972375b7803e11c6849b7cde648c06b4a79
3
+ metadata.gz: d33a842934c9b3979fac8b0abb80548316a3a41b54884dfbca05d24684eed208
4
+ data.tar.gz: 11461fb6325472b2f39add42a9552029dafc0f31c0825faf867fef80983fd51f
5
5
  SHA512:
6
- metadata.gz: 60d962bf4c22ec4809fb536f1afb8301cf8c2f5d62bb12531eb90aebdba133b791a687a9d0cecc2ac2914284a8b3b26b490cca6483079ed96565d7ce7157f261
7
- data.tar.gz: 40187fcaa6a732e2b37d00ff15fbf4e2a0fafe9c45a3c776a60204e470d053236167cf4aaf923ca1bc9e6bf9678724f174f409ac7dbb22dfaa72271f2dfd37c4
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/README.md CHANGED
@@ -1,7 +1,12 @@
1
- git-gsub
1
+ git-gsub-ruby
2
2
  ========
3
3
 
4
- Evaluate ruby gsub script on git.
4
+ Replace text for all git controlled files by ruby gsub.
5
+
6
+ You can control the gsub replacement with the ruby script.
7
+
8
+ Inspired by [git-gsub](https://github.com/fujimura/git-gsub)
9
+
5
10
 
6
11
  ### Usage
7
12
 
@@ -22,11 +27,9 @@ Edit your .gitconfig file
22
27
  # add new line
23
28
  gsub = !git-gsub-ruby
24
29
  ```
25
- Or `git config`
30
+ Or use `git config`
26
31
 
27
- ``` bash
28
- git config --global alias.gs '!git-gsub-ruby'
29
- ```
32
+ $ git config --global alias.gsub '!git-gsub-ruby'
30
33
 
31
34
 
32
35
  ## Contributing
data/exe/git-gsub-ruby CHANGED
@@ -3,42 +3,49 @@
3
3
  require "open3"
4
4
  require 'optparse'
5
5
  require 'git/gsub/ruby'
6
+ require 'pathname'
6
7
 
7
8
  def text_file?(filename)
8
9
  file_type, status = Open3.capture2e("file", filename.to_s)
9
10
  status.success? && file_type.include?("text")
10
11
  end
11
12
 
12
- ARGV.extend OptionParser::Arguable
13
- ARGV.options.version = Git::Gsub::Ruby::VERSION
14
- 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
15
19
  Usage:
16
- ruby #{File.basename(__FILE__)} [options] from to [glob]
17
- from - gsub from string or ruby script
18
- to - gsub to string or ruby script
19
- glob - (optional)ruby glob pattern.
20
- options:
21
- -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.
22
24
 
23
- example:
24
- git gsub hoge piyo
25
- git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
26
- 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'
27
- 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
28
34
 
29
- opts = ARGV.getopts('e', 'eval')
30
- evaluate = (opts['e'] || opts['eval']) ? true : false
35
+ opts.parse!(ARGV)
31
36
 
32
37
  begin
33
38
  raise "Invalid argument" if ARGV.size != 2 && ARGV.size != 3
34
39
 
35
- from_str, to_str, glob = ARGV
40
+ from_str, to_str, glob_pattern = ARGV
36
41
  from = evaluate ? eval(from_str) : from_str
37
- glob ||= '**/*'
38
- 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)
39
45
 
40
46
  lsfiles = `git ls-files`
41
- 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
+
42
49
  files.each do |path|
43
50
  next unless text_file? path
44
51
  buf = nil
@@ -57,7 +64,7 @@ begin
57
64
  end
58
65
  end
59
66
  if buf
60
- puts "replaced:#{path}"
67
+ puts "replaced:#{path}" if debug
61
68
  open(path, "w") do |f|
62
69
  f.write buf
63
70
  end
@@ -65,6 +72,8 @@ begin
65
72
  end
66
73
  rescue => ex
67
74
  puts ex.message
68
- puts ex.backtrace
69
- puts ARGV.options.help
75
+ if debug
76
+ puts ex.backtrace
77
+ end
78
+ puts opts.help
70
79
  end
@@ -1,7 +1,7 @@
1
1
  module Git
2
2
  module Gsub
3
3
  module Ruby
4
- VERSION = "0.1.0"
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.0
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-25 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.0)
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