Class: MailDiode::Settings

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Settings

Returns a new instance of Settings.



54
55
56
57
58
59
60
61
62
63
# File 'lib/settings.rb', line 54

def initialize(config_file)
	@settings = {}
	File.foreach(config_file) do | line |
		line = line.gsub(/#.*/, '').strip
		if !line.empty?
			component, keyword, args = line.split(' ', 3)
			load_setting(component.downcase, keyword.downcase, args)
		end
	end
end

Class Method Details

.default_fileObject



99
100
101
# File 'lib/settings.rb', line 99

def Settings.default_file
	'/etc/maildiode/maildiode.conf'
end

Instance Method Details

#get_int(component, keyword, default_value) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/settings.rb', line 91

def get_int(component, keyword, default_value)
	value = get_setting(component, keyword)
	if(!value)
		return default_value
	end
	return value.to_i
end

#get_setting(component, keyword) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/settings.rb', line 79

def get_setting(component, keyword)
	component_settings = get_settings(component)
	if(!component_settings)
		return nil
	end
	setting = component_settings.get_setting(keyword)
	if(!setting)
	  return nil
    end
    return setting.value
end

#get_settings(component) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/settings.rb', line 70

def get_settings(component)
	component_settings = @settings[component]
	if(!component_settings)
		component_settings = ComponentSettings.new
		@settings[component] = component_settings
	end
	return component_settings
end

#load_setting(component, keyword, args) ⇒ Object



65
66
67
68
# File 'lib/settings.rb', line 65

def load_setting(component, keyword, args)
	component_settings = get_settings(component)
	component_settings.add(SingleSetting.new(keyword, args))
end