Module: ConcertoConfig::ConfigStore
- Defined in:
- lib/concerto_client/config_store.rb
Constant Summary collapse
- @@path =
nil
Class Method Summary collapse
- .initialize_path ⇒ Object
- .read_config(name, default = '') ⇒ Object
-
.write_config(name, value) ⇒ Object
Write a config to the read/write configuration location.
Class Method Details
.initialize_path ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/concerto_client/config_store.rb', line 38 def self.initialize_path @@ropath = File.join(LiveImage.mountpoint, 'concerto', 'config') if LiveImage.readonly? @@path = '/tmp/concerto/config' else @@path = @@ropath end FileUtils.mkdir_p @@path end |
.read_config(name, default = '') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/concerto_client/config_store.rb', line 10 def self.read_config(name, default='') initialize_path if not @@path file = File.join(@@path, name) rofile = File.join(@@ropath, name) # Check the read/write config location first. If nothing there, # check the read-only location. If nothing is there, return default. # This way writes can be made at runtime on read-only media while # still allowing some settings to be "baked into" the media. if File.exist?(file) IO.read(file) elsif File.exist?(rofile) IO.read(rofile) else default end end |
.write_config(name, value) ⇒ Object
Write a config to the read/write configuration location.
29 30 31 32 33 34 35 36 |
# File 'lib/concerto_client/config_store.rb', line 29 def self.write_config(name, value) initialize_path if not @@path file = File.join(@@path, name) File.open(file, 'w') do |f| f.write value end end |