Class: Bosh::Agent::Settings
- Extended by:
- Forwardable
- Defined in:
- lib/bosh_agent/settings.rb
Class Method Summary collapse
-
.load(cache_path = nil) ⇒ Object
Loads settings specific to the current infrastructure, and then caches the result to disk.
Instance Method Summary collapse
- #cache ⇒ Object
-
#initialize(file) ⇒ Settings
constructor
A new instance of Settings.
- #load ⇒ Object
Constructor Details
#initialize(file) ⇒ Settings
Returns a new instance of Settings.
19 20 21 22 |
# File 'lib/bosh_agent/settings.rb', line 19 def initialize(file) @settings = {} @cache_file = file end |
Class Method Details
.load(cache_path = nil) ⇒ Object
Loads settings specific to the current infrastructure, and then caches the result to disk. If it can’t fetch settings, it will fall back to previously cached settings
12 13 14 15 16 17 |
# File 'lib/bosh_agent/settings.rb', line 12 def self.load(cache_path=nil) settings = new(cache_path || Config.settings_file) settings.load settings.cache settings end |
Instance Method Details
#cache ⇒ Object
32 33 34 35 36 37 |
# File 'lib/bosh_agent/settings.rb', line 32 def cache json = Yajl::Encoder.encode(@settings) File.open(@cache_file, 'w') do |file| file.write(json) end end |
#load ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/bosh_agent/settings.rb', line 24 def load load_from_infrastructure cache rescue LoadSettingsError => e logger.info("failed to load infrastructure settings: #{e.}") load_from_cache end |