Class: ItunesController::ServerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/itunesController/config.rb

Overview

This class is used to save read and store the server configuration }

Examples:

{

<itunesController>
    <users>
        <user username="test" password="test"/>
    </users>
</itunesController>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServerConfig

The constructor



43
44
45
46
# File 'lib/itunesController/config.rb', line 43

def initialize()
    @port =nil
    @interfaceAddress = "localhost"
end

Instance Attribute Details

#interfaceAddressObject

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

#passwordObject

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

#portObject

The port number the server is listening on



39
40
41
# File 'lib/itunesController/config.rb', line 39

def port
  @port
end

#usernameObject

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