Class: AppConfig

Inherits:
Object show all
Defined in:
lib/taskjuggler/AppConfig.rb

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

Instance Method Summary collapse

Constructor Details

#initializeAppConfig

Returns a new instance of AppConfig.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/taskjuggler/AppConfig.rb', line 25

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

.appNameObject



73
74
75
# File 'lib/taskjuggler/AppConfig.rb', line 73

def AppConfig.appName
  @@appName
end

.appName=(name) ⇒ Object



69
70
71
# File 'lib/taskjuggler/AppConfig.rb', line 69

def AppConfig.appName=(name)
  @@appName = name
end

.authorsObject



81
82
83
# File 'lib/taskjuggler/AppConfig.rb', line 81

def AppConfig.authors
  @@authors
end

.authors=(authors) ⇒ Object



77
78
79
# File 'lib/taskjuggler/AppConfig.rb', line 77

def AppConfig.authors=(authors)
  @@authors = authors
end

.contactObject



97
98
99
# File 'lib/taskjuggler/AppConfig.rb', line 97

def AppConfig.contact
  @@contact
end

.contact=(contact) ⇒ Object



93
94
95
# File 'lib/taskjuggler/AppConfig.rb', line 93

def AppConfig.contact=(contact)
  @@contact = contact
end


89
90
91
# File 'lib/taskjuggler/AppConfig.rb', line 89

def AppConfig.copyright
  @@copyright
end

.copyright=(copyright) ⇒ Object



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

def AppConfig.copyright=(copyright)
  @@copyright = copyright
end

.dataDirs(baseDir = 'data') ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/taskjuggler/AppConfig.rb', line 109

def AppConfig.dataDirs(baseDir = 'data')
  dirs = dataSearchDirs(baseDir)
  # Remove non-existing directories from the list again
  dirs.delete_if do |dir|
    !File.exist?(dir)
  end
  dirs
end

.dataFile(fileName) ⇒ Object



153
154
155
156
157
158
# File 'lib/taskjuggler/AppConfig.rb', line 153

def AppConfig.dataFile(fileName)
  dirs = dataDirs
  dirs.each { |d| return d + fileName if File.exist?(d + fileName) }

  nil
end

.dataFiles(fileName) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/taskjuggler/AppConfig.rb', line 145

def AppConfig.dataFiles(fileName)
  files = []
  dirs = dataDirs
  dirs.each { |d| files << d + fileName if File.exist?(d + fileName) }

  files
end

.dataSearchDirs(baseDir = 'data') ⇒ Object



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
143
# File 'lib/taskjuggler/AppConfig.rb', line 118

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

.licenseObject



105
106
107
# File 'lib/taskjuggler/AppConfig.rb', line 105

def AppConfig.license
  @@license
end

.license=(license) ⇒ Object



101
102
103
# File 'lib/taskjuggler/AppConfig.rb', line 101

def AppConfig.license=(license)
  @@license = license
end

.packageInfoObject



65
66
67
# File 'lib/taskjuggler/AppConfig.rb', line 65

def AppConfig.packageInfo
  @@packageInfo
end

.packageInfo=(info) ⇒ Object



61
62
63
# File 'lib/taskjuggler/AppConfig.rb', line 61

def AppConfig.packageInfo=(info)
  @@packageInfo = info
end

.packageNameObject



49
50
51
# File 'lib/taskjuggler/AppConfig.rb', line 49

def AppConfig.packageName
  @@packageName
end

.packageName=(name) ⇒ Object



45
46
47
# File 'lib/taskjuggler/AppConfig.rb', line 45

def AppConfig.packageName=(name)
  @@packageName = name
end

.softwareNameObject



57
58
59
# File 'lib/taskjuggler/AppConfig.rb', line 57

def AppConfig.softwareName
  @@softwareName
end

.softwareName=(name) ⇒ Object



53
54
55
# File 'lib/taskjuggler/AppConfig.rb', line 53

def AppConfig.softwareName=(name)
  @@softwareName = name
end

.versionObject



41
42
43
# File 'lib/taskjuggler/AppConfig.rb', line 41

def AppConfig.version
  @@version
end

.version=(version) ⇒ Object



37
38
39
# File 'lib/taskjuggler/AppConfig.rb', line 37

def AppConfig.version=(version)
  @@version = version
end