Class: ParticlePi::Settings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/particlepi/settings.rb', line 6

def path
  @path
end

#valuesObject (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_pathObject



25
26
27
# File 'lib/particlepi/settings.rb', line 25

def default_path
  File.join(ParticlePi.project_root, "settings/particle.json")
end

#loadObject



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

#saveObject



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