Class: Isaac::Config::Data

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ Data

Returns a new instance of Data.



68
69
70
71
# File 'lib/isaac/config.rb', line 68

def initialize(filename=nil)
  self.config_filename = filename || default_config_file
  @config = read_config(config_filename)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



66
67
68
# File 'lib/isaac/config.rb', line 66

def config
  @config
end

#config_filenameObject

Returns the value of attribute config_filename.



66
67
68
# File 'lib/isaac/config.rb', line 66

def config_filename
  @config_filename
end

Class Method Details

.load(filename = nil) ⇒ Object



95
96
97
# File 'lib/isaac/config.rb', line 95

def self.load(filename=nil)
  Isaac::Config.data = new(filename)
end

Instance Method Details

#config_dirObject



73
74
75
# File 'lib/isaac/config.rb', line 73

def config_dir
  File.exist?('config') && File.directory?('config') ? './config' : '.'
end

#default_config_fileObject



77
78
79
# File 'lib/isaac/config.rb', line 77

def default_config_file
  File.join(config_dir, "config.yml")
end

#networksObject



81
82
83
# File 'lib/isaac/config.rb', line 81

def networks
  config.keys
end

#read_config(filename = nil) ⇒ Object



85
86
87
88
89
# File 'lib/isaac/config.rb', line 85

def read_config(filename=nil)
  self.config_filename = filename if filename
  Isaac.logger.debug "Loading config from #{config_filename}"
  YAML.load_file(config_filename) rescue {"default" => {}}
end

#to_yamlObject



91
92
93
# File 'lib/isaac/config.rb', line 91

def to_yaml
  config.to_yaml
end