Class: ItunesController::ServerConfig
- Inherits:
-
Object
- Object
- ItunesController::ServerConfig
- Defined in:
- lib/itunesController/config.rb
Overview
This class is used to save read and store the server configuration }
Instance Attribute Summary collapse
-
#interfaceAddress ⇒ Object
The DNS/IP address of the interface the server is binding too.
-
#password ⇒ Object
The password of the user used to connect to login to the server.
-
#port ⇒ Object
The port number the server is listening on.
-
#username ⇒ Object
The username of the user used to connect to login to the server.
Class Method Summary collapse
-
.readConfig(configFile) ⇒ ItunesController::ServerConfig
A class scoped method used to read the server configuration from a file See the class description for a example of the configuration file format.
Instance Method Summary collapse
-
#initialize ⇒ ServerConfig
constructor
The constructor.
Constructor Details
#initialize ⇒ ServerConfig
The constructor
43 44 45 46 |
# File 'lib/itunesController/config.rb', line 43 def initialize() @port =nil @interfaceAddress = "localhost" end |
Instance Attribute Details
#interfaceAddress ⇒ Object
The DNS/IP address of the interface the server is binding too.
39 40 41 |
# File 'lib/itunesController/config.rb', line 39 def interfaceAddress @interfaceAddress end |
#password ⇒ Object
The password of the user used to connect to login to the server
39 40 41 |
# File 'lib/itunesController/config.rb', line 39 def password @password end |
#port ⇒ Object
The port number the server is listening on
39 40 41 |
# File 'lib/itunesController/config.rb', line 39 def port @port end |
#username ⇒ Object
The username of the user used to connect to login to the server
39 40 41 |
# File 'lib/itunesController/config.rb', line 39 def username @username end |
Class Method Details
.readConfig(configFile) ⇒ ItunesController::ServerConfig
A class scoped method used to read the server configuration from a file See the class description for a example of the configuration file format. If their are any problems loading the configuration, then the application is exited and a error message is printed to the stderr console stream.
54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/itunesController/config.rb', line 54 def self.readConfig(configFile) if (!File.exists? configFile) raise("Unable to find configuration file: "+configFile) end config=ServerConfig.new begin doc=Document.new(File.new( configFile )) rootEl = doc.root.elements["/itunesController"] if (rootEl==nil) raise("Unable to find parse configuartion file, can't find node /itunesController") end if (rootEl.attributes["port"]!=nil && rootEl.attributes["port"]!="") config.port = rootEl.attributes["port"].to_i end if (rootEl.attributes["interfaceAddress"]!=nil && rootEl.attributes["interfaceAddress"]!="") config.interfaceAddress = rootEl.attributes["interfaceAddress"] end doc.elements.each("/itunesController/users/user") { |userElement| config.username=userElement.attributes["username"] config.password=userElement.attributes["password"] } rescue EOFError raise("Unable to read or parse the configuration file: " + configFile) end if (config.username==nil) raise("Username name missing in configuration file") end if (config.password==nil) raise("Password name missing in configuration file") end return config end |