Class: PodsOrz::OrzEnvDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/podsorz/core/Config/orz_env_detector.rb

Instance Method Summary collapse

Instance Method Details

#check_directory(directoryPath) ⇒ Object



6
7
8
9
10
11
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 6

def check_directory(directoryPath)
	is_directory = File.directory?(directoryPath)
	Logger.error("Detect failure, directory path error: #{directoryPath}") unless is_directory

	is_directory
end

#copy_content_from_podfile(directoryPath) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 34

def copy_content_from_podfile(directoryPath)
	podfile_path = File.expand_path("Podfile", directoryPath)
	total_sentences = []
	File.open(podfile_path, "r") { |io|  
		total_sentences = io.readlines
	}

	dest_path = File.expand_path("Podfile_orz.rb", directoryPath)
	File.open(dest_path, "w+") {|io|
		total_sentences.each do |sentence|
			io.write(sentence)
		end
	}
	
end

#detect_podfile(directoryPath) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 13

def detect_podfile(directoryPath)
	podfile_path = File.expand_path("Podfile", directoryPath)
	result = File.exist?(podfile_path)
	unless result
		Logger.warning("Podfile not exist, create empty Podfile")
		IO.popen("cd #{directoryPath};pod init")
	end
end

#detect_podfile_orz(directoryPath) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 22

def detect_podfile_orz(directoryPath)
	podfile_path = File.expand_path("Podfile_orz.rb", directoryPath)
	result = File.exist?(podfile_path)
	unless result
		Logger.error("Podfile_orz.rb not exist,auto generate one which content is copy from origin Podfile")
		IO.popen("cd #{directoryPath};touch Podfile_orz.rb")
		copy_content_from_podfile(directoryPath)
	end
	
	result
end

#detect_PodsOrzConfig(directoryPath) ⇒ Object



50
51
52
53
54
55
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 50

def detect_PodsOrzConfig(directoryPath)
	orzconfig_path = File.expand_path("PodsOrzConfig.rb", directoryPath)
	orzconfig_result = File.exist?(orzconfig_path)

	generate_default_config(orzconfig_path) unless orzconfig_result
end

#generate_default_config(file_path) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/podsorz/core/Config/orz_env_detector.rb', line 57

def generate_default_config(file_path)
	Logger.warning("PodsOrzConfig not exist, generate default config")
	file_name = File.basename(file_path)
	directory = File.dirname(file_path)
	IO.popen("cd #{directory};touch #{file_name}") { |io|
		templet_config_path = File.expand_path("./orz_config_templet.rb", File.dirname(__FILE__))
		File.open(templet_config_path, "r") { |templet_file|
			File.open(file_path, "w+") { |file|  
				templet_file.readlines.each {|line|
					puts line
					file.write(line)
				} 
			}
		}
	}
end