Class: Eagle::Config
- Inherits:
-
Object
- Object
- Eagle::Config
- Defined in:
- lib/eagle/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
-
.config(config_path = nil) ⇒ Object
singleton config.
- .default_config_locations ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
- #hostname ⇒ Object
-
#initialize(config_path = nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(config_path = nil) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/eagle/config.rb', line 6 def initialize(config_path=nil) locations = Config.default_config_locations locations = [config_path] if config_path locations.each do |file| @data = YAML.load(File.read(file)) if File.exist?(file) end unless @data raise ConfigNotFoundException, "Not found at #{locations.join(', ')}" end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/eagle/config.rb', line 5 def data @data end |
Class Method Details
.config(config_path = nil) ⇒ Object
singleton config
29 30 31 |
# File 'lib/eagle/config.rb', line 29 def self.config(config_path=nil) @config || Config.new(config_path) end |
.default_config_locations ⇒ Object
37 38 39 40 41 |
# File 'lib/eagle/config.rb', line 37 def self.default_config_locations filename = 'eagle.yml' home = File.('~') locations = ["#{home}/.#{filename}", "/etc/#{filename}", filename] end |
.reset ⇒ Object
33 34 35 |
# File 'lib/eagle/config.rb', line 33 def self.reset @config = nil end |
Instance Method Details
#hostname ⇒ Object
24 25 26 |
# File 'lib/eagle/config.rb', line 24 def hostname @data['hostname'] ||%x(hostname) end |