module Bandshell::ConfigStore

Public Class Methods

config_exists?(name) click to toggle source

check if a config exists

# File lib/bandshell/config_store.rb, line 29
def self.config_exists?(name)
  initialize_path if not @@path
  file = File.join(@@path, name)
  rofile = File.join(@@ropath, name)
  File.exist?(file) || File.exist?(rofile)
end
delete_config(name) click to toggle source

Delete a config from the filesystem

# File lib/bandshell/config_store.rb, line 47
def self.delete_config(name)
  initialize_path if not @@path
  file = File.join(@@path, name)
  FileUtils.rm(file)
end
initialize_path() click to toggle source
# File lib/bandshell/config_store.rb, line 53
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='') click to toggle source
# File lib/bandshell/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) click to toggle source

Write a config to the read/write configuration location.

# File lib/bandshell/config_store.rb, line 37
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