Base configuration class

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#Base class for configuration routines
class ConfigurationBase
protected
#Setting active preference
def self.active name
@active = name
end
#Setting preference itself
def self.preference content
#Initializing array for the first time
@preferences = {} if @preferences == nil
if block_given?
block_result = yield Hash.new
if block_result.kind_of? Hash
@preferences[content] = block_result
end
else
#Adding new preference
@preferences[content.keys.first] = content.values.first
end
end
#Getting actual preference value
def self.[] name
#Exiting with nil if nothing defined
return nil if @preferences == nil
unless @active == nil
return @preferences[@active][name]
else
return @preferences[@preferences.keys.first][name]
end
end
end