Class: XscreenUsbUnlocker::ConfigBlob

Inherits:
Hash
  • Object
show all
Defined in:
lib/xscreen_usb_unlocker/config.rb

Constant Summary collapse

BaseDir =
"/home/ebrodeur/.config/erniebrodeur"

Instance Method Summary collapse

Constructor Details

#initializeConfigBlob

Returns a new instance of ConfigBlob.



7
8
9
10
# File 'lib/xscreen_usb_unlocker/config.rb', line 7

def initialize
  FileUtils.mkdir_p BaseDir if !Dir.exist? BaseDir
  load
end

Instance Method Details

#fileObject



12
13
14
# File 'lib/xscreen_usb_unlocker/config.rb', line 12

def file
  "#{BaseDir}/#{App.name}.json"
end

#loadObject



31
32
33
34
35
36
# File 'lib/xscreen_usb_unlocker/config.rb', line 31

def load
  if File.exist? self.file
    h = Yajl.load open(file, 'r').read
    h.each { |k,v| self[k.to_sym] = v}
  end
end

#saveObject



16
17
18
19
20
21
22
23
24
# File 'lib/xscreen_usb_unlocker/config.rb', line 16

def save
  if any?
    # I do this the long way because I want an immediate sync.
    f = open(file, 'w')
    f.write Yajl.dump self
    f.sync
    f.close
  end
end

#save!Object



26
27
28
29
# File 'lib/xscreen_usb_unlocker/config.rb', line 26

def save!
  FileUtils.rm file if File.file? file
  save
end