Class: Eagle::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject

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_locationsObject



37
38
39
40
41
# File 'lib/eagle/config.rb', line 37

def self.default_config_locations
  filename  = 'eagle.yml'
  home      = File.expand_path('~')
  locations = ["#{home}/.#{filename}", "/etc/#{filename}", filename]
end

.resetObject



33
34
35
# File 'lib/eagle/config.rb', line 33

def self.reset
  @config = nil
end

Instance Method Details

#hostnameObject



24
25
26
# File 'lib/eagle/config.rb', line 24

def hostname
  @data['hostname'] ||%x(hostname)
end