Class: Rbeapi::Client::Config
- Inherits:
-
IniFile
- Object
- IniFile
- Rbeapi::Client::Config
- Defined in:
- lib/rbeapi/client.rb
Constant Summary collapse
- CONFIG_SEARCH_PATH =
['~/.eapi.conf', '/mnt/flash/eapi.conf']
Instance Method Summary collapse
-
#add_connection(name, values) ⇒ Object
Adds a new connection section to the current configuration.
-
#get_connection(name) ⇒ nil, Hash<String, String> Returns a hash of the connection properities from the loaded config. This method will return nil if the connection name is not found.
Returns the configuration for the connection specified.
-
#initialize(opts = {}) ⇒ Config
constructor
The Config class holds the loaded configuration file data.
-
#read(filename) ⇒ Object
This method will read the specified filename and load its contents into the instance.
-
#reload(opts = {}) ⇒ Object
This method will cause the config to be loaded.
Constructor Details
#initialize(opts = {}) ⇒ Config
The Config class holds the loaded configuration file data. It is a subclass of IniFile. The Config class will automatically search for a filename to load (if none provided) and load the data when the object is instantiated.
169 170 171 172 173 |
# File 'lib/rbeapi/client.rb', line 169 def initialize(opts = {}) super(parameter: ':') @filename = opts.fetch(:filename, nil) autoload end |
Instance Method Details
#add_connection(name, values) ⇒ Object
Adds a new connection section to the current configuration
243 244 245 |
# File 'lib/rbeapi/client.rb', line 243 def add_connection(name, values) self["connection:#{name}"] = values end |
#get_connection(name) ⇒ nil, Hash<String, String> Returns a hash of the connection properities from the loaded config. This method will return nil if the connection name is not found.
Returns the configuration for the connection specified
232 233 234 235 |
# File 'lib/rbeapi/client.rb', line 232 def get_connection(name) return nil unless sections.include? "connection:#{name}" self["connection:#{name}"] end |
#read(filename) ⇒ Object
This method will read the specified filename and load its contents into the instance. It will also add the default localhost entry if it doesn’t exist in the conf file
203 204 205 206 207 208 |
# File 'lib/rbeapi/client.rb', line 203 def read(filename) super(filename: filename) unless get_connection 'localhost' add_connection('localhost', transport: 'socket') end end |
#reload(opts = {}) ⇒ Object
This method will cause the config to be loaded. The process of finding the configuration will be repeated so it is possible a different conf file could be choosen if the original file was removed or a new file added higher on the search priority list
218 219 220 |
# File 'lib/rbeapi/client.rb', line 218 def reload(opts = {}) autoload opts end |