Class: AdaptrexConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/adaptrex/adaptrexconfig.rb

Overview

Utility class to manage the .adaptrex.config file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdaptrexConfig

Returns a new instance of AdaptrexConfig.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/adaptrex/adaptrexconfig.rb', line 26

def initialize
	@configFilePath = Etc.getpwuid.dir + "/.adaptrex.config"
	if not File.exist?(@configFilePath)
		puts "Welcome To Adaptrex Tools!".blue
		puts "The first time you run the Tools, we need to learn a little about your environment."

		#	Weblib Path is requires... make sure we set it up right away
		promptForWeblibPath
	else
		read
		updateInstalledSDKs
	end
	write
end

Instance Attribute Details

#adaptrexVersionsObject

Returns the value of attribute adaptrexVersions.



23
24
25
# File 'lib/adaptrex/adaptrexconfig.rb', line 23

def adaptrexVersions
  @adaptrexVersions
end

#extVersionsObject

Returns the value of attribute extVersions.



23
24
25
# File 'lib/adaptrex/adaptrexconfig.rb', line 23

def extVersions
  @extVersions
end

#touchVersionsObject

Returns the value of attribute touchVersions.



23
24
25
# File 'lib/adaptrex/adaptrexconfig.rb', line 23

def touchVersions
  @touchVersions
end

#weblibPathObject

Returns the value of attribute weblibPath.



23
24
25
# File 'lib/adaptrex/adaptrexconfig.rb', line 23

def weblibPath
  @weblibPath
end

Instance Method Details

#promptForWeblibPathObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/adaptrex/adaptrexconfig.rb', line 82

def promptForWeblibPath
    puts "Enter the path of the folder containing your AdaptrexJS, ExtJS and Sencha Touch SDKs."
	print " : "
	userInput = STDIN.gets.chomp
	self.weblibPath = userInput
	
	if not File.directory?userInput
		puts "You entered an invalid path".err
		return promptForWeblibPath
	end		

	updateInstalledSDKs
	
	errorMsg = []
	if adaptrexVersions.length == 0
		errorMsg.push("You must have an AdaptrexJS folder.".indent)
	end
	if (extVersions.length + touchVersions.length == 0)
		errorMsg.push("You must have at least one ExtJS or Sencha Touch SDK folder.".indent)
	end
	if errorMsg.length > 0
		puts "The folder you entered is missing the required SDKs".err
		puts errorMsg.join("\n")
		return promptForWeblibPath
	end
	
	puts "Your weblib folder has been successfully configured.\n\n".success
end

#readObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/adaptrex/adaptrexconfig.rb', line 41

def read
	config = File.new(@configFilePath, "r")
	while (line = config.gets)
		line.strip!
		if (line[0] != "#" and line[0] != "=")
			eq = line.index("=")
			if (eq)
				key = line[0..eq - 1].strip
				value = line[eq + 1..-1].strip

				if key == 		"weblib.path" 		then self.weblibPath = value
				elsif key == 	"adaptrex.versions" then self.adaptrexVersions = value.split(",")
				elsif key == 	"ext.versions" 		then self.extVersions = value.split(",")
				elsif key == 	"touch.versions" 	then self.touchVersions = value.split(",")
				end
			end
		end
	end
	config.close
end

#updateInstalledSDKsObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/adaptrex/adaptrexconfig.rb', line 111

def updateInstalledSDKs
	self.adaptrexVersions = []
	self.extVersions = []
	self.touchVersions = []
	
	Pathname.new(self.weblibPath).children.select {|path|
		folderName = path.basename.to_s
		if folderName =~ /\s/
			puts(("Weblib folder name cannot contain spaces (" + folderName + ")").success)
			puts "It will not be available to your applications.\n".indent
		else
			if 		folderName.start_with?"adaptrex" 	then self.adaptrexVersions.push(folderName)
			elsif 	folderName.start_with?"ext" 		then self.extVersions.push(folderName)
			elsif 	folderName.start_with?"sencha" 		then self.touchVersions.push(folderName)
			end
		end
	}
end

#writeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/adaptrex/adaptrexconfig.rb', line 62

def write
	settings = File.open(@configFilePath, "w")
	settings.puts "#"
	settings.puts "#  Adaptrex Configuration"
	settings.puts "#  ----------------------"
	settings.puts "#"
	settings.puts "#  This file is automatically generated and maintained by Adaptrex Tools."
	settings.puts "#"
	settings.puts "\n\n"
	settings.puts "weblib.path = " 			+ self.weblibPath
	settings.puts "adaptrex.versions = " 	+ self.adaptrexVersions.join(",")
	if self.extVersions.length > 0
		settings.puts "ext.versions = " 	+ self.extVersions.join(",")
	end
	if self.touchVersions.length > 0
		settings.puts "touch.versions = " + self.touchVersions.join(",")
	end
	settings.close
end