replace_class 1.0.4 → 1.1.0

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
  SHA1:
3
- metadata.gz: fa2b3b79d722f81f43ffd7ae68bd09c174de41c4
4
- data.tar.gz: 357656a30282e74e1bf4a41f0c0e90576d818eac
3
+ metadata.gz: 93756cd03e277667eb390f809b93bfe2046b1903
4
+ data.tar.gz: ac76b4c8abad372bf8808484f1255ce240b40f99
5
5
  SHA512:
6
- metadata.gz: c04067957d028bdedc8b3e2f6da63ea1e8f8afa4cf5ea6a0ec5af5632f5613f439908111f6d5caf588d47b37ddef62164699a52c5be46715437e71f490daced5
7
- data.tar.gz: 744490a0ff22a8d4f61e5032c5cea66faec40df682cd07571bf07fb3a0d35a38c91ad31241c92853d16caad5bc60b400fd24da4176c1e78e1b0129d8f3199c2f
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
- # 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
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
- regex = Regexp.new("([^a-zA-Z]|^)(#{$options[:source]})([^a-zA-Z]|$)")
59
- line_or_filename =~ regex
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
- 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
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ReplaceClass
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/replace_class.rb CHANGED
@@ -1,5 +1 @@
1
-
2
- lib = File.expand_path('../',__FILE__)
3
- lib = $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
1
  require 'replace_class/replace_class'
5
- ReplaceClass.start
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
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-18 00:00:00.000000000 Z
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: