replace_class 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/replace_class/replace_class.rb +67 -52
- data/lib/replace_class/utils.rb +2 -5
- data/lib/replace_class/version.rb +1 -1
- data/lib/replace_class.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93756cd03e277667eb390f809b93bfe2046b1903
|
4
|
+
data.tar.gz: ac76b4c8abad372bf8808484f1255ce240b40f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b816a6620cc30e26cad328843bd27d8dc71f5ca55f63ec30742c536a1434182417e91344e52bdb73a7da0b18b449160d72a58cba57c8a1cdf8e593f1f56f7a
|
7
|
+
data.tar.gz: 366ba8524c0ecb447e586c7dff05b8c8aaaba6de6e4470d97b5f42e579b84d243e307616cb2ebdc972a8f034e08d95c4219391b28173a92eafe3c8b84708ea36
|
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require 'replace_class/utils'
|
5
4
|
require 'replace_class/option_parser'
|
5
|
+
require 'replace_class/utils'
|
6
6
|
|
7
7
|
#
|
8
8
|
# main module for this gem
|
@@ -19,46 +19,51 @@ module ReplaceClass
|
|
19
19
|
#
|
20
20
|
def self.start
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
50
|
end
|
51
51
|
|
52
|
-
#:stopdoc:
|
53
|
-
|
54
52
|
##
|
55
53
|
# short cut for matching string
|
56
54
|
def self.match?(line_or_filename)
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
|
56
|
+
regex = Regexp.new("([^a-zA-Z0-9]|^)#{$options[:source]}([^a-zA-Z0-9]|$)")
|
57
|
+
line_or_filename =~ regex
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.replace(line_or_filename)
|
61
|
+
|
62
|
+
regex = Regexp.new("([^a-zA-Z0-9]|^)#{$options[:source]}([^a-zA-Z0-9]|$)")
|
63
|
+
line_or_filename.gsub(regex, "\\1#{$options[:dest]}\\2")
|
60
64
|
end
|
61
65
|
|
66
|
+
#:stopdoc:
|
62
67
|
##
|
63
68
|
# traverse dir for checking replacement
|
64
69
|
def self.checkDir(dir)
|
@@ -71,14 +76,14 @@ module ReplaceClass
|
|
71
76
|
isFile = File.file?(filePath)
|
72
77
|
isDir = File.directory?(filePath)
|
73
78
|
|
74
|
-
if isDir
|
79
|
+
if isDir then
|
75
80
|
|
76
81
|
if !ReplaceClass::Util.hidden?(filename) && !ReplaceClass::Util.check_ignore_dir(filename)
|
77
82
|
checkDir(filePath)
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
81
|
-
if isFile
|
86
|
+
if isFile then
|
82
87
|
|
83
88
|
unless ReplaceClass::Util.check_valid_with_file(filename)
|
84
89
|
next
|
@@ -87,21 +92,31 @@ module ReplaceClass
|
|
87
92
|
if ReplaceClass::Util.hidden?(filename)
|
88
93
|
next
|
89
94
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
95
|
+
|
96
|
+
if match?(filename)
|
97
|
+
puts "matching filename: #{filename}"
|
98
|
+
newname = replace(filename)
|
99
|
+
File.rename(filePath, File.join(dir, newname))
|
100
|
+
filePath = File.join(dir, newname)
|
101
|
+
end
|
102
|
+
|
103
|
+
lines = IO.readlines(filePath)
|
104
|
+
lines.each_index do |index|
|
105
|
+
|
106
|
+
line = lines[index]
|
107
|
+
if match?(line)
|
108
|
+
puts "matching in : [#{filename} : #{index + 1}] with content:\n#{line}"
|
109
|
+
newline = replace(line)
|
110
|
+
lines[index] = newline
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
file_content = lines.join
|
115
|
+
File.open(filePath, "r+") do |file|
|
116
|
+
file.write(file_content)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
105
120
|
end
|
106
121
|
|
107
|
-
end
|
122
|
+
end
|
data/lib/replace_class/utils.rb
CHANGED
@@ -3,7 +3,7 @@ module ReplaceClass
|
|
3
3
|
##
|
4
4
|
# filename util
|
5
5
|
class Util
|
6
|
-
|
6
|
+
|
7
7
|
##
|
8
8
|
# valid file types
|
9
9
|
VALID_FILE_TYPE = [".h", ".m", ".pbxproj",".swift"]
|
@@ -35,14 +35,11 @@ module ReplaceClass
|
|
35
35
|
if File.extname(filename) == ext
|
36
36
|
return true
|
37
37
|
end
|
38
|
-
|
39
38
|
end
|
40
39
|
end
|
41
40
|
false
|
42
|
-
|
43
41
|
end
|
44
42
|
|
45
|
-
|
46
43
|
end
|
47
44
|
|
48
|
-
end
|
45
|
+
end
|
data/lib/replace_class.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1.0
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: easy way to replace class name in xcode using ruby
|
14
14
|
email:
|