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 = nil) ⇒ Settings

Returns a new instance of Settings.



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

def initialize(config_file = nil)
		@settings = {}
		if(config_file)
      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
end

Class Method Details

.default_fileObject



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

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

Instance Method Details

#get_int(component, keyword, default_value) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/settings.rb', line 93

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



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

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



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

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



67
68
69
70
# File 'lib/settings.rb', line 67

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