Class: BigBrother::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/big_brother/settings.rb

Class Method Summary collapse

Class Method Details

.defaultsObject



12
13
14
15
16
17
18
# File 'lib/big_brother/settings.rb', line 12

def self.defaults
  {
    "history_file" => File.expand_path("~/.bash_history"),
    "push_url" => "https://ministry-of-truth.herokuapp.com/",
    "api_key" => nil
  }
end

.get(setting) ⇒ Object



26
27
28
# File 'lib/big_brother/settings.rb', line 26

def self.get(setting)
  @settings[setting]
end

.loadObject



20
21
22
23
24
# File 'lib/big_brother/settings.rb', line 20

def self.load
  touch settings_file
  @settings = defaults.merge(JSON.parse(File.read(settings_file)))
  save
end

.saveObject



35
36
37
# File 'lib/big_brother/settings.rb', line 35

def self.save
  File.write(settings_file, @settings.to_json)
end

.set(setting, value) ⇒ Object



30
31
32
33
# File 'lib/big_brother/settings.rb', line 30

def self.set(setting, value)
  @settings[setting] = value
  save
end

.settings_fileObject



4
5
6
# File 'lib/big_brother/settings.rb', line 4

def self.settings_file
  @settings_file || File.expand_path("~/.big_brother.json")
end

.settings_file=(path) ⇒ Object



8
9
10
# File 'lib/big_brother/settings.rb', line 8

def self.settings_file=(path)
  @settings_file = path
end

.touch(file_name) ⇒ Object



39
40
41
# File 'lib/big_brother/settings.rb', line 39

def self.touch(file_name)
  File.write(file_name, "{}") unless File.exists? file_name
end