replace_class 1.0.1
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 +7 -0
- data/bin/replace_class +5 -0
- data/lib/replace_class.rb +122 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b18a50b799f86df3fc08105f309171e5ae680fd2
|
4
|
+
data.tar.gz: e779cf4842b5cab161d002655864e4d4b6dbfa22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3335c5e970aff08087feb56b1c476615d5d91a60b24a804964579665381c8fbdbdc948aac19d9320c167075618d6716fe742b41f0de5f375966f706aa1ffd341
|
7
|
+
data.tar.gz: 11bfba9a6658bb85ef00e7957ca266fb19208c98d079bf4b31fb0f849c8e99229a09d5b6fc34e9287c140de331c45bc3366e966c2f3bef2fc8a08ea77bb0a7bd
|
data/bin/replace_class
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
# option parse
|
7
|
+
@options = {}
|
8
|
+
@parser = OptionParser.new do |opt|
|
9
|
+
|
10
|
+
opt.banner = "Usage: [update_name -s source -d dest path]"
|
11
|
+
|
12
|
+
opt.on('-s', '--source sourceClass', 'Source class name for replacement') do |value|
|
13
|
+
@options[:source] = value
|
14
|
+
end
|
15
|
+
|
16
|
+
opt.on('-d', '--dest destClass', 'Dest class name for replacement') do |value|
|
17
|
+
@options[:dest] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
opt.on('-f', '--force', 'No interaction with user') do |value|
|
21
|
+
@options[:force] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
opt.on('-y', '--yes', 'Same to force option') do |value|
|
25
|
+
@options[:force] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
@parser.parse!
|
31
|
+
|
32
|
+
# check option
|
33
|
+
if !@options.has_key?(:source) || !@options.has_key?(:dest)
|
34
|
+
puts @parser.help
|
35
|
+
exit false
|
36
|
+
end
|
37
|
+
|
38
|
+
# define
|
39
|
+
@valid_file_type = [".h", ".m", ".pbxproj",".swift"]
|
40
|
+
@ignore_dir = ["Pods", "DerivedData"]
|
41
|
+
|
42
|
+
# check file if hide
|
43
|
+
def hidden?(filename)
|
44
|
+
filename =~ /^\./
|
45
|
+
end
|
46
|
+
|
47
|
+
# check dir if ignore
|
48
|
+
def check_ignore_dir(filename)
|
49
|
+
@ignore_dir.find_index(filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
# check file if valid
|
53
|
+
def check_valid_with_file(filename)
|
54
|
+
|
55
|
+
if filename !~ /^\./ then
|
56
|
+
|
57
|
+
@valid_file_type.each do |ext|
|
58
|
+
|
59
|
+
if File.extname(filename) == ext
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
false
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def match?(line_or_filename)
|
70
|
+
|
71
|
+
regex = Regexp.new("([^a-zA-Z]|^)(#{@options[:source]})([^a-zA-Z]|$)")
|
72
|
+
line_or_filename =~ regex
|
73
|
+
end
|
74
|
+
|
75
|
+
# main function
|
76
|
+
def checkDir(dir)
|
77
|
+
|
78
|
+
aDir = Dir.new(dir)
|
79
|
+
aDir.each do |filename|
|
80
|
+
|
81
|
+
filePath = File.join(dir, filename)
|
82
|
+
|
83
|
+
isFile = File.file?(filePath)
|
84
|
+
isDir = File.directory?(filePath)
|
85
|
+
|
86
|
+
if isDir
|
87
|
+
|
88
|
+
if !hidden?(filename) && !check_ignore_dir(filename)
|
89
|
+
checkDir(filePath)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if isFile
|
94
|
+
|
95
|
+
if !check_valid_with_file(filename)
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
if hidden?(filename)
|
100
|
+
next
|
101
|
+
end
|
102
|
+
|
103
|
+
if match?(filename)
|
104
|
+
puts "matching regex to file: #{filename}"
|
105
|
+
end
|
106
|
+
|
107
|
+
lines = IO.readlines(filePath)
|
108
|
+
lines.each_index do |index|
|
109
|
+
|
110
|
+
line = lines[index]
|
111
|
+
if match?(line)
|
112
|
+
puts "matching regex in line : [#{filename} : #{index + 1}] with content:\n#{line}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# perform
|
120
|
+
src_root = Pathname.new(ARGV.count == 4 ? __FILE__ : ARGV.last).realpath
|
121
|
+
checkDir(src_root)
|
122
|
+
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: replace_class
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MickeyHub
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- 791331313@qq.com
|
16
|
+
executables:
|
17
|
+
- replace_class
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/replace_class
|
22
|
+
- lib/replace_class.rb
|
23
|
+
homepage: http://github.com/MickeyHub/ReplaceClassName
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.4.5.1
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: An Neat Script to Replace Class Name Globally for Xcode
|
47
|
+
test_files: []
|