replace_class 1.0.3 → 1.0.4
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/README.rdoc +2 -0
- data/bin/replace_class +2 -0
- data/lib/replace_class/option_parser.rb +46 -0
- data/lib/replace_class/replace_class.rb +107 -0
- data/lib/replace_class/utils.rb +48 -0
- data/lib/replace_class/version.rb +3 -0
- data/lib/replace_class.rb +4 -133
- data/replace_class.gemspec +8 -3
- metadata +16 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa2b3b79d722f81f43ffd7ae68bd09c174de41c4
|
4
|
+
data.tar.gz: 357656a30282e74e1bf4a41f0c0e90576d818eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c04067957d028bdedc8b3e2f6da63ea1e8f8afa4cf5ea6a0ec5af5632f5613f439908111f6d5caf588d47b37ddef62164699a52c5be46715437e71f490daced5
|
7
|
+
data.tar.gz: 744490a0ff22a8d4f61e5032c5cea66faec40df682cd07571bf07fb3a0d35a38c91ad31241c92853d16caad5bc60b400fd24da4176c1e78e1b0129d8f3199c2f
|
data/README.rdoc
ADDED
data/bin/replace_class
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
module ReplaceClass
|
2
|
+
|
3
|
+
##
|
4
|
+
# wrapper for built-in OptionParser
|
5
|
+
class OptParser
|
6
|
+
|
7
|
+
##
|
8
|
+
# start parse options
|
9
|
+
def self.parse # :yield: parser, cli_opts
|
10
|
+
|
11
|
+
unless block_given? then
|
12
|
+
exit false
|
13
|
+
end
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
parser = OptionParser.new do |opt|
|
17
|
+
|
18
|
+
opt.banner = "Usage: [update_name -s source -d dest path]"
|
19
|
+
|
20
|
+
opt.on('-s', '--source sourceClass', 'Source class name for replacement') do |value|
|
21
|
+
options[:source] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
opt.on('-d', '--dest destClass', 'Dest class name for replacement') do |value|
|
25
|
+
options[:dest] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
opt.on('-f', '--force', 'No interaction with user') do |value|
|
29
|
+
options[:force] = value
|
30
|
+
end
|
31
|
+
|
32
|
+
opt.on('-y', '--yes', 'Same to force option') do |value|
|
33
|
+
options[:force] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
parser.parse!
|
39
|
+
|
40
|
+
yield parser, options
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'replace_class/utils'
|
5
|
+
require 'replace_class/option_parser'
|
6
|
+
|
7
|
+
#
|
8
|
+
# main module for this gem
|
9
|
+
#
|
10
|
+
# === Example
|
11
|
+
# ReplaceClass.start
|
12
|
+
#
|
13
|
+
module ReplaceClass
|
14
|
+
|
15
|
+
#--
|
16
|
+
# TODO: finish replace job
|
17
|
+
#++
|
18
|
+
# replace class from source to dest (include file name)
|
19
|
+
#
|
20
|
+
def self.start
|
21
|
+
|
22
|
+
# option parse
|
23
|
+
ReplaceClass::OptParser.parse do |parser, options|
|
24
|
+
|
25
|
+
$options = options
|
26
|
+
|
27
|
+
# check option
|
28
|
+
if !options.has_key?(:source) || !options.has_key?(:dest)
|
29
|
+
puts parser.help
|
30
|
+
exit false
|
31
|
+
end
|
32
|
+
|
33
|
+
# check project file when no path
|
34
|
+
if ARGV.empty? then
|
35
|
+
if Dir["*.xcodeproj"].empty? then
|
36
|
+
puts "current directory have not a filename end with 'xcodeproj'"
|
37
|
+
exit false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# perform
|
42
|
+
if ARGV.empty? then
|
43
|
+
src_root = File.expand_path('../', __FILE__)
|
44
|
+
else
|
45
|
+
src_root = File.expand_path(ARGV.last)
|
46
|
+
end
|
47
|
+
|
48
|
+
checkDir(src_root)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#:stopdoc:
|
53
|
+
|
54
|
+
##
|
55
|
+
# short cut for matching string
|
56
|
+
def self.match?(line_or_filename)
|
57
|
+
|
58
|
+
regex = Regexp.new("([^a-zA-Z]|^)(#{$options[:source]})([^a-zA-Z]|$)")
|
59
|
+
line_or_filename =~ regex
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# traverse dir for checking replacement
|
64
|
+
def self.checkDir(dir)
|
65
|
+
|
66
|
+
aDir = Dir.new(dir)
|
67
|
+
aDir.each do |filename|
|
68
|
+
|
69
|
+
filePath = File.join(dir, filename)
|
70
|
+
|
71
|
+
isFile = File.file?(filePath)
|
72
|
+
isDir = File.directory?(filePath)
|
73
|
+
|
74
|
+
if isDir
|
75
|
+
|
76
|
+
if !ReplaceClass::Util.hidden?(filename) && !ReplaceClass::Util.check_ignore_dir(filename)
|
77
|
+
checkDir(filePath)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if isFile
|
82
|
+
|
83
|
+
unless ReplaceClass::Util.check_valid_with_file(filename)
|
84
|
+
next
|
85
|
+
end
|
86
|
+
|
87
|
+
if ReplaceClass::Util.hidden?(filename)
|
88
|
+
next
|
89
|
+
end
|
90
|
+
|
91
|
+
if match?(filename)
|
92
|
+
puts "matching regex to file: #{filename}"
|
93
|
+
end
|
94
|
+
|
95
|
+
lines = IO.readlines(filePath)
|
96
|
+
lines.each_index do |index|
|
97
|
+
|
98
|
+
line = lines[index]
|
99
|
+
if match?(line)
|
100
|
+
puts "matching regex in line : [#{filename} : #{index + 1}] with content:\n#{line}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ReplaceClass
|
2
|
+
|
3
|
+
##
|
4
|
+
# filename util
|
5
|
+
class Util
|
6
|
+
|
7
|
+
##
|
8
|
+
# valid file types
|
9
|
+
VALID_FILE_TYPE = [".h", ".m", ".pbxproj",".swift"]
|
10
|
+
|
11
|
+
##
|
12
|
+
# ignore dirs
|
13
|
+
IGNORE_DIR = ["Pods", "DerivedData"]
|
14
|
+
|
15
|
+
##
|
16
|
+
# check file if hide
|
17
|
+
def self.hidden?(filename)
|
18
|
+
filename =~ /^\./
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# check dir if ignore
|
23
|
+
def self.check_ignore_dir(filename)
|
24
|
+
IGNORE_DIR.find_index(filename)
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# check file if valid
|
29
|
+
def self.check_valid_with_file(filename)
|
30
|
+
|
31
|
+
if filename !~ /^\./ then
|
32
|
+
|
33
|
+
VALID_FILE_TYPE.each do |ext|
|
34
|
+
|
35
|
+
if File.extname(filename) == ext
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
false
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/replace_class.rb
CHANGED
@@ -1,134 +1,5 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
|
5
|
-
# option parse
|
6
|
-
@options = {}
|
7
|
-
@parser = OptionParser.new do |opt|
|
8
|
-
|
9
|
-
opt.banner = "Usage: [update_name -s source -d dest path]"
|
10
|
-
|
11
|
-
opt.on('-s', '--source sourceClass', 'Source class name for replacement') do |value|
|
12
|
-
@options[:source] = value
|
13
|
-
end
|
14
|
-
|
15
|
-
opt.on('-d', '--dest destClass', 'Dest class name for replacement') do |value|
|
16
|
-
@options[:dest] = value
|
17
|
-
end
|
18
|
-
|
19
|
-
opt.on('-f', '--force', 'No interaction with user') do |value|
|
20
|
-
@options[:force] = value
|
21
|
-
end
|
22
|
-
|
23
|
-
opt.on('-y', '--yes', 'Same to force option') do |value|
|
24
|
-
@options[:force] = value
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
@parser.parse!
|
30
|
-
|
31
|
-
# check option
|
32
|
-
if !@options.has_key?(:source) || !@options.has_key?(:dest)
|
33
|
-
puts @parser.help
|
34
|
-
exit false
|
35
|
-
end
|
36
|
-
|
37
|
-
# check project file when no path
|
38
|
-
if ARGV.empty? then
|
39
|
-
if Dir["*.xcodeproj"].empty? then
|
40
|
-
puts "current directory have not a filename end with 'xcodeproj'"
|
41
|
-
exit false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# define
|
46
|
-
@valid_file_type = [".h", ".m", ".pbxproj",".swift"]
|
47
|
-
@ignore_dir = ["Pods", "DerivedData"]
|
48
|
-
|
49
|
-
# check file if hide
|
50
|
-
def hidden?(filename)
|
51
|
-
filename =~ /^\./
|
52
|
-
end
|
53
|
-
|
54
|
-
# check dir if ignore
|
55
|
-
def check_ignore_dir(filename)
|
56
|
-
@ignore_dir.find_index(filename)
|
57
|
-
end
|
58
|
-
|
59
|
-
# check file if valid
|
60
|
-
def check_valid_with_file(filename)
|
61
|
-
|
62
|
-
if filename !~ /^\./ then
|
63
|
-
|
64
|
-
@valid_file_type.each do |ext|
|
65
|
-
|
66
|
-
if File.extname(filename) == ext
|
67
|
-
return true
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
false
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def match?(line_or_filename)
|
77
|
-
|
78
|
-
regex = Regexp.new("([^a-zA-Z]|^)(#{@options[:source]})([^a-zA-Z]|$)")
|
79
|
-
line_or_filename =~ regex
|
80
|
-
end
|
81
|
-
|
82
|
-
# main function
|
83
|
-
def checkDir(dir)
|
84
|
-
|
85
|
-
aDir = Dir.new(dir)
|
86
|
-
aDir.each do |filename|
|
87
|
-
|
88
|
-
filePath = File.join(dir, filename)
|
89
|
-
|
90
|
-
isFile = File.file?(filePath)
|
91
|
-
isDir = File.directory?(filePath)
|
92
|
-
|
93
|
-
if isDir
|
94
|
-
|
95
|
-
if !hidden?(filename) && !check_ignore_dir(filename)
|
96
|
-
checkDir(filePath)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
if isFile
|
101
|
-
|
102
|
-
if !check_valid_with_file(filename)
|
103
|
-
next
|
104
|
-
end
|
105
|
-
|
106
|
-
if hidden?(filename)
|
107
|
-
next
|
108
|
-
end
|
109
|
-
|
110
|
-
if match?(filename)
|
111
|
-
puts "matching regex to file: #{filename}"
|
112
|
-
end
|
113
|
-
|
114
|
-
lines = IO.readlines(filePath)
|
115
|
-
lines.each_index do |index|
|
116
|
-
|
117
|
-
line = lines[index]
|
118
|
-
if match?(line)
|
119
|
-
puts "matching regex in line : [#{filename} : #{index + 1}] with content:\n#{line}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# perform
|
127
|
-
if ARGV.empty? then
|
128
|
-
src_root = File.expand_path('../', __FILE__)
|
129
|
-
else
|
130
|
-
src_root File.expand_path(ARGV.last)
|
131
|
-
end
|
132
|
-
|
133
|
-
checkDir(src_root)
|
134
1
|
|
2
|
+
lib = File.expand_path('../',__FILE__)
|
3
|
+
lib = $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'replace_class/replace_class'
|
5
|
+
ReplaceClass.start
|
data/replace_class.gemspec
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# stub: replace_class 1.0.0 ruby lib
|
3
3
|
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'replace_class/version.rb'
|
7
|
+
|
4
8
|
Gem::Specification.new do |s|
|
5
9
|
s.name = "replace_class"
|
6
|
-
s.version =
|
7
|
-
|
10
|
+
s.version = ReplaceClass::VERSION
|
11
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
|
12
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
8
13
|
s.require_paths = ["lib"]
|
9
14
|
s.authors = ["MickeyHub"]
|
10
15
|
s.date = Time.now.strftime("%Y-%m-%d")
|
@@ -14,5 +19,5 @@ Gem::Specification.new do |s|
|
|
14
19
|
s.licenses = ["MIT"]
|
15
20
|
s.summary = "An Neat Script to Replace Class Name Globally for Xcode"
|
16
21
|
s.description = "easy way to replace class name in xcode using ruby"
|
17
|
-
s.executables = s.files.grep(%
|
22
|
+
s.executables = s.files.grep(%r{^bin/}){|f| File.basename(f)}
|
18
23
|
end
|
metadata
CHANGED
@@ -1,34 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: replace_class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MickeyHub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: easy way to replace class name in xcode using ruby
|
14
14
|
email:
|
15
15
|
- 791331313@qq.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- replace_class
|
17
18
|
extensions: []
|
18
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.rdoc
|
21
|
+
- LICENSE
|
19
22
|
files:
|
20
23
|
- ".gitignore"
|
21
24
|
- LICENSE
|
22
25
|
- README.md
|
26
|
+
- README.rdoc
|
23
27
|
- bin/replace_class
|
24
28
|
- lib/replace_class.rb
|
29
|
+
- lib/replace_class/option_parser.rb
|
30
|
+
- lib/replace_class/replace_class.rb
|
31
|
+
- lib/replace_class/utils.rb
|
32
|
+
- lib/replace_class/version.rb
|
25
33
|
- replace_class.gemspec
|
26
34
|
homepage: http://github.com/MickeyHub/ReplaceClassName
|
27
35
|
licenses:
|
28
36
|
- MIT
|
29
37
|
metadata: {}
|
30
38
|
post_install_message:
|
31
|
-
rdoc_options:
|
39
|
+
rdoc_options:
|
40
|
+
- "--main"
|
41
|
+
- README.rdoc
|
32
42
|
require_paths:
|
33
43
|
- lib
|
34
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -43,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
53
|
version: '0'
|
44
54
|
requirements: []
|
45
55
|
rubyforge_project:
|
46
|
-
rubygems_version: 2.4.
|
56
|
+
rubygems_version: 2.4.6
|
47
57
|
signing_key:
|
48
58
|
specification_version: 4
|
49
59
|
summary: An Neat Script to Replace Class Name Globally for Xcode
|