Module: CovaIO

Included in:
Cova
Defined in:
lib/covaio.rb

Instance Method Summary collapse

Instance Method Details

#_io_app_exists(name) ⇒ Object



64
65
66
# File 'lib/covaio.rb', line 64

def _io_app_exists(name)
	return File.directory?(@dir_cova_apps_home + "/" + name)
end

#_io_clone_repo(repo, dir) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/covaio.rb', line 89

def _io_clone_repo (repo, dir)
	pwd = Dir.pwd
	Dir.chdir(dir)
	_io_exec "git clone #{repo}"
	reponame = File.basename(repo, ".*")
	Dir.chdir(reponame)
	#_io_exec "git remote add upstream #{repo}"
	#Dir.chdir(pwd)
	return _io_isdir(dir + "/" + reponame)
end

#_io_cpdir(src, targ) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/covaio.rb', line 122

def _io_cpdir(src, targ)
	if _io_isdir src and not _io_isdir targ, false
		`cp -r #{src} #{targ}`
		return _io_isdir targ
	end
	return false
end

#_io_cpfile(src, targ) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/covaio.rb', line 130

def _io_cpfile(src, targ)
	if _io_isfile src and not _io_isfile targ, false
		`cp #{src} #{targ}`
		return _io_isfile targ
	end
	return false
end

#_io_exec(cmd) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/covaio.rb', line 17

def _io_exec(cmd)
	pipe = IO.popen(cmd)
	puts cmd
	while (line = pipe.gets)
	  print line		
	end
end

#_io_exec_xctool(cmd = "build", config = "Debug", sdk = "iphonesimulator") ⇒ Object



25
26
27
# File 'lib/covaio.rb', line 25

def _io_exec_xctool(cmd="build", config="Debug", sdk="iphonesimulator")
	_io_exec @dir_xctool_home + "/xctool.sh -workspace cova.xcworkspace -scheme Cova -configuration #{config} -sdk #{sdk} #{cmd}"
end

#_io_initObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/covaio.rb', line 3

def _io_init
	@dir_user_home 			= File.expand_path("~")
	@dir_cova_home 			= File.expand_path("~/.cova")
	@dir_cova_ios_mods_home = File.expand_path("~/.cocoapods/cova")
	@dir_cocoapods_home 	= File.expand_path("~/.cocoapods")
	@dir_xctool_home 		= File.expand_path("~/.cova/xctool")
	@dir_xcode_build_home 	= File.expand_path("~/Library/Developer/Xcode/DerivedData")
	@dir_cova_apps_home 	= File.expand_path("~/.cova/apps")

	@repo_cova 			    = "git://github.com/dancali/cova.git"
	@repo_cova_ios_mods		= "git://github.com/dancali/cova-ios-mods.git"
	@repo_xctool			= "git://github.com/facebook/xctool.git"
end

#_io_isdir(dir, expected = true) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/covaio.rb', line 34

def _io_isdir(dir,expected=true)
	_log_line (expected ? "Expecting #{dir} to exist" : "Ensuring #{dir} does not exist")
	if File.directory?(dir)
		expected ? _log_line_ok : _log_line_error
  		return true
  	end		  	

  	if expected
	  	_log_line_error
	else
		_log_line_ok
	end
  	return false
end

#_io_isfile(file, expected = true) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/covaio.rb', line 49

def _io_isfile(file,expected=true)
	_log_line (expected ? "Expecting #{file} to exist" : "Ensuring #{file} does not exist")
	if File.exist?(file)
		expected ? _log_line_ok : _log_line_error
  		return true
  	end		  	

  	if expected
	  	_log_line_error
	else
		_log_line_ok
	end
  	return false
end

#_io_lndir(src, targ) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/covaio.rb', line 113

def _io_lndir(src, targ)
	if _io_isdir src and not _io_isdir targ, false
		`ln -s #{src} #{targ}`
		return _io_isdir targ
	end

	return false
end

#_io_ls(dir) ⇒ Object



85
86
87
# File 'lib/covaio.rb', line 85

def _io_ls(dir)
	Dir.foreach(dir) {|entry| puts "#{entry}" unless (entry =='.' || entry == '..') }
end

#_io_mkdir(dir) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/covaio.rb', line 138

def _io_mkdir(dir)
	if File.directory?(dir)
		return true
	end
	
	_log_line "Creating #{dir}"
	`mkdir #{dir}`
	File.directory?(dir) ? _log_line_ok : _log_line_error
	return File.directory?(dir)
end

#_io_open_app_source(name) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/covaio.rb', line 68

def _io_open_app_source(name)
	if not _io_app_exists name
		_log_info "Looks like the app #{name} does not exist. Please create if first."
		_log_line_error
		return false
	end

	app_project = "#{@dir_cova_apps_home}/#{name}/ios/cova.xcworkspace"
	if not File.exist?(app_project)
		_log_info "Looks like the app #{name} was never build. Please build it first."
		return false
	end

	_io_exec "open #{app_project}"
	return true
end

#_io_pod_add_repo(name, repo) ⇒ Object



29
30
31
32
# File 'lib/covaio.rb', line 29

def _io_pod_add_repo(name, repo)
	_io_exec("pod repo add #{name} #{repo}")
	return _io_isdir(@dir_cocoapods_home + "/" + name)
end

#_io_rmdir(dir) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/covaio.rb', line 100

def _io_rmdir(dir)
	_log_line "Removing #{dir}"
	if File.directory?(dir)
		`rm -rf #{dir}`
	  	if File.directory?(dir)
	  		_log_line_error
	  		return false
		end
	end
	_log_line_ok
	return true
end