Module: ReplaceClass

Defined in:
lib/replace_class/replace_class.rb,
lib/replace_class/utils.rb,
lib/replace_class/version.rb,
lib/replace_class/option_parser.rb

Overview

main module for this gem

Example

ReplaceClass.start

Defined Under Namespace

Classes: OptParser, Util

Constant Summary collapse

VERSION =
'1.0.4'

Class Method Summary collapse

Class Method Details

.checkDir(dir) ⇒ Object

traverse dir for checking replacement



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/replace_class/replace_class.rb', line 64

def self.checkDir(dir)

	aDir = Dir.new(dir)
	aDir.each do |filename|

		filePath = File.join(dir, filename)

		isFile = File.file?(filePath)
		isDir = File.directory?(filePath)

		if isDir 

			if !ReplaceClass::Util.hidden?(filename) && !ReplaceClass::Util.check_ignore_dir(filename)
				checkDir(filePath)
			end
		end

		if isFile

			unless ReplaceClass::Util.check_valid_with_file(filename)
				next
			end

			if ReplaceClass::Util.hidden?(filename)
				next
			end
         
            if match?(filename)
                puts "matching regex to file: #{filename}"
            end

			lines = IO.readlines(filePath)
			lines.each_index do |index| 

				line = lines[index]
				if match?(line)
					puts "matching regex in line : [#{filename} : #{index + 1}] with content:\n#{line}"
				end
			end
		end
	end
end

.match?(line_or_filename) ⇒ Boolean

short cut for matching string

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/replace_class/replace_class.rb', line 56

def self.match?(line_or_filename)
   
   regex = Regexp.new("([^a-zA-Z]|^)(#{$options[:source]})([^a-zA-Z]|$)")
   line_or_filename =~ regex
end

.startObject

– TODO: finish replace job ++ replace class from source to dest (include file name)



20
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
50
# File 'lib/replace_class/replace_class.rb', line 20

def self.start

	# option parse
       ReplaceClass::OptParser.parse do |parser, options|

       	$options = options

		# check option
		if !options.has_key?(:source) || !options.has_key?(:dest)
			puts parser.help
			exit false
		end

		# check project file when no path
		if ARGV.empty? then 
		   if Dir["*.xcodeproj"].empty? then
		       puts "current directory have not a filename end with 'xcodeproj'"
		       exit false
		   end
		end

		# perform
		if ARGV.empty? then
			src_root = File.expand_path('../', __FILE__)
		else
			src_root = File.expand_path(ARGV.last)
		end

		checkDir(src_root)
	end
end