Class: PingMon::Config
- Inherits:
-
Object
- Object
- PingMon::Config
- Defined in:
- lib/pingmon/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config_file = PingMon::DEFAULT_CONFIG_FILE) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #loaded? ⇒ Boolean
Constructor Details
#initialize(config_file = PingMon::DEFAULT_CONFIG_FILE) ⇒ Config
Returns a new instance of Config.
8 9 10 11 |
# File 'lib/pingmon/config.rb', line 8 def initialize(config_file=PingMon::DEFAULT_CONFIG_FILE) @config_file = config_file @loaded = false end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
13 14 15 |
# File 'lib/pingmon/config.rb', line 13 def config_file @config_file end |
Class Method Details
.build_config(where = PingMon::DEFAULT_CONFIG_FILE) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/pingmon/config.rb', line 39 def self.build_config(where=PingMon::DEFAULT_CONFIG_FILE) from = File.dirname(__FILE__) + '/../../config/pingmon.yml' File.copy(File.(from), where) PingMon.Log << "Created configuration file '#{where}'." if PingMon.log where end |
Instance Method Details
#load ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pingmon/config.rb', line 15 def load raise ConfigFileNotFound.new("Configuration file '#{config_file}' could not be found!") unless File.exists?(config_file) PingMon.log << "Loading configuration from '#{@config_file}'" if PingMon.log text = ERB.new(File.read(config_file)).result hash = YAML.load(text) base_config = (hash.symbolize_keys[:config]).stringify_keys base_config.keys.each do |key| instance_variable_set("@#{key}", base_config[key]) self.class.class_eval do define_method(key.to_sym) { instance_variable_get("@#{key}") } end end @loaded = true self end |
#loaded? ⇒ Boolean
35 36 37 |
# File 'lib/pingmon/config.rb', line 35 def loaded? @loaded end |