Class: AppConfig
Overview
This class provides central management of configuration data to an application. It stores the version number, the name of the application and the suite it belongs to. It also holds copyright and license information. These infos have to be set in the main module of the application right after launch. Then, all other modules can retrieve them from the global instance as needed.
Class Method Summary collapse
- .appName ⇒ Object
- .appName=(name) ⇒ Object
- .authors ⇒ Object
- .authors=(authors) ⇒ Object
- .contact ⇒ Object
- .contact=(contact) ⇒ Object
- .copyright ⇒ Object
- .copyright=(copyright) ⇒ Object
- .dataDirs(baseDir = 'data') ⇒ Object
- .dataFile(fileName) ⇒ Object
- .dataFiles(fileName) ⇒ Object
- .dataSearchDirs(baseDir = 'data') ⇒ Object
- .license ⇒ Object
- .license=(license) ⇒ Object
- .packageInfo ⇒ Object
- .packageInfo=(info) ⇒ Object
- .packageName ⇒ Object
- .packageName=(name) ⇒ Object
- .softwareName ⇒ Object
- .softwareName=(name) ⇒ Object
- .version ⇒ Object
- .version=(version) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ AppConfig
constructor
A new instance of AppConfig.
Constructor Details
#initialize ⇒ AppConfig
Returns a new instance of AppConfig.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/taskjuggler/AppConfig.rb', line 24 def initialize @@version = '0.0.0' @@packageName = 'unnamed' @@softwareName = 'unnamed' @@packageInfo = 'no info' @@appName = 'unnamed' @@authors = [] @@copyright = [] @@contact = 'not specified' @@license = 'no license' end |
Class Method Details
.appName ⇒ Object
72 73 74 |
# File 'lib/taskjuggler/AppConfig.rb', line 72 def AppConfig.appName @@appName end |
.appName=(name) ⇒ Object
68 69 70 |
# File 'lib/taskjuggler/AppConfig.rb', line 68 def AppConfig.appName=(name) @@appName = name end |
.authors ⇒ Object
80 81 82 |
# File 'lib/taskjuggler/AppConfig.rb', line 80 def AppConfig. @@authors end |
.authors=(authors) ⇒ Object
76 77 78 |
# File 'lib/taskjuggler/AppConfig.rb', line 76 def AppConfig.() @@authors = end |
.contact ⇒ Object
96 97 98 |
# File 'lib/taskjuggler/AppConfig.rb', line 96 def AppConfig.contact @@contact end |
.contact=(contact) ⇒ Object
92 93 94 |
# File 'lib/taskjuggler/AppConfig.rb', line 92 def AppConfig.contact=(contact) @@contact = contact end |
.copyright ⇒ Object
88 89 90 |
# File 'lib/taskjuggler/AppConfig.rb', line 88 def AppConfig.copyright @@copyright end |
.copyright=(copyright) ⇒ Object
84 85 86 |
# File 'lib/taskjuggler/AppConfig.rb', line 84 def AppConfig.copyright=(copyright) @@copyright = copyright end |
.dataDirs(baseDir = 'data') ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/taskjuggler/AppConfig.rb', line 108 def AppConfig.dataDirs(baseDir = 'data') dirs = dataSearchDirs(baseDir) # Remove non-existing directories from the list again dirs.delete_if do |dir| !File.exist?(dir.untaint) end dirs end |
.dataFile(fileName) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/taskjuggler/AppConfig.rb', line 152 def AppConfig.dataFile(fileName) dirs = dataDirs dirs.each { |d| return d + fileName if File.exist?(d + fileName) } nil end |
.dataFiles(fileName) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/taskjuggler/AppConfig.rb', line 144 def AppConfig.dataFiles(fileName) files = [] dirs = dataDirs dirs.each { |d| files << d + fileName if File.exist?(d + fileName) } files end |
.dataSearchDirs(baseDir = 'data') ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/taskjuggler/AppConfig.rb', line 117 def AppConfig.dataSearchDirs(baseDir = 'data') rubyLibDir = RbConfig::CONFIG['rubylibdir'] rubyBaseDir, versionDir = rubyLibDir.scan(/(.*\/)(.*)/)[0] dirs = [] if ENV['TASKJUGGLER_DATA_PATH'] ENV['TASKJUGGLER_DATA_PATH'].split(':').each do |path| dirs << path + "/#{baseDir}/" end end # Find the data dir relative to the source of this file. This should # always work. dirs << File.join(File.dirname(__FILE__), '..', '..', baseDir) # This hopefully works for all setups. Otherwise we have to add more # alternative pathes. # This one is for RPM based distros like Novell dirs << rubyBaseDir + "gems/" + versionDir + '/gems/' \ + @@packageName + '-' + @@version + "/#{baseDir}/" # This one is for Debian based distros dirs << rubyLibDir + '/gems/' \ + @@packageName + '-' + @@version + "/#{baseDir}/" dirs end |
.license ⇒ Object
104 105 106 |
# File 'lib/taskjuggler/AppConfig.rb', line 104 def AppConfig.license @@license end |
.license=(license) ⇒ Object
100 101 102 |
# File 'lib/taskjuggler/AppConfig.rb', line 100 def AppConfig.license=(license) @@license = license end |
.packageInfo ⇒ Object
64 65 66 |
# File 'lib/taskjuggler/AppConfig.rb', line 64 def AppConfig.packageInfo @@packageInfo end |
.packageInfo=(info) ⇒ Object
60 61 62 |
# File 'lib/taskjuggler/AppConfig.rb', line 60 def AppConfig.packageInfo=(info) @@packageInfo = info end |
.packageName ⇒ Object
48 49 50 |
# File 'lib/taskjuggler/AppConfig.rb', line 48 def AppConfig.packageName @@packageName end |
.packageName=(name) ⇒ Object
44 45 46 |
# File 'lib/taskjuggler/AppConfig.rb', line 44 def AppConfig.packageName=(name) @@packageName = name end |
.softwareName ⇒ Object
56 57 58 |
# File 'lib/taskjuggler/AppConfig.rb', line 56 def AppConfig.softwareName @@softwareName end |
.softwareName=(name) ⇒ Object
52 53 54 |
# File 'lib/taskjuggler/AppConfig.rb', line 52 def AppConfig.softwareName=(name) @@softwareName = name end |