Class: AptlyCli::AptlyLoad
- Inherits:
-
Object
- Object
- AptlyCli::AptlyLoad
- Defined in:
- lib/aptly_load.rb
Overview
Load aptly-cli configuration
Instance Method Summary collapse
- #config ⇒ Object
-
#configure(opts = {}) ⇒ Object
Configure through hash.
-
#configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file.
-
#initialize ⇒ AptlyLoad
constructor
A new instance of AptlyLoad.
Constructor Details
#initialize ⇒ AptlyLoad
Returns a new instance of AptlyLoad.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/aptly_load.rb', line 12 def initialize @log = Logger.new(STDOUT) @log.level = Logger::WARN # Configuration defaults @config = { proto: 'http', server: '127.0.0.1', port: 8082 } @valid_config_keys = @config.keys + [:username, :password, :debug] end |
Instance Method Details
#config ⇒ Object
8 9 10 |
# File 'lib/aptly_load.rb', line 8 def config @config end |
#configure(opts = {}) ⇒ Object
Configure through hash
27 28 29 30 31 32 33 |
# File 'lib/aptly_load.rb', line 27 def configure(opts = {}) opts.each do |k, v| config[k.to_sym] = v if @valid_config_keys.include? k.to_sym end @config end |
#configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aptly_load.rb', line 36 def configure_with(path_to_yaml_file) if path_to_yaml_file begin config = YAML.load(IO.read(path_to_yaml_file)) rescue Errno::ENOENT @log.warn( "YAML configuration file couldn\'t be found at " \ "#{path_to_yaml_file}. Using defaults.") return @config rescue Psych::SyntaxError @log.warn( 'YAML configuration file contains invalid syntax. Using defaults.') return @config end else config = {} end configure(config) end |