Class: BigBrother::Settings
- Inherits:
-
Object
- Object
- BigBrother::Settings
- Defined in:
- lib/big_brother/settings.rb
Class Method Summary collapse
- .defaults ⇒ Object
- .get(setting) ⇒ Object
- .load ⇒ Object
- .save ⇒ Object
- .set(setting, value) ⇒ Object
- .settings_file ⇒ Object
- .settings_file=(path) ⇒ Object
- .touch(file_name) ⇒ Object
Class Method Details
.defaults ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/big_brother/settings.rb', line 12 def self.defaults { "history_file" => File.("~/.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 |
.load ⇒ Object
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 |
.save ⇒ Object
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_file ⇒ Object
4 5 6 |
# File 'lib/big_brother/settings.rb', line 4 def self.settings_file @settings_file || File.("~/.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 |