Class: ParticlePi::Settings
- Inherits:
-
Object
- Object
- ParticlePi::Settings
- Defined in:
- lib/particlepi/settings.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #default_path ⇒ Object
-
#initialize(path = default_path) ⇒ Settings
constructor
A new instance of Settings.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(path = default_path) ⇒ Settings
Returns a new instance of Settings.
8 9 10 11 |
# File 'lib/particlepi/settings.rb', line 8 def initialize(path = default_path) @path = path @values = {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/particlepi/settings.rb', line 6 def path @path end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
7 8 9 |
# File 'lib/particlepi/settings.rb', line 7 def values @values end |
Instance Method Details
#default_path ⇒ Object
25 26 27 |
# File 'lib/particlepi/settings.rb', line 25 def default_path File.join(ParticlePi.project_root, "settings/particle.json") end |
#load ⇒ Object
13 14 15 16 17 18 |
# File 'lib/particlepi/settings.rb', line 13 def load settings_str = IO.read(path) @values = JSON.parse(settings_str) unless settings_str.empty? rescue Errno::ENOENT # Ignore missing file end |
#save ⇒ Object
20 21 22 23 |
# File 'lib/particlepi/settings.rb', line 20 def save settings_str = JSON.pretty_generate(values) IO.write(path, settings_str) end |