Sha256: 43dcf18671e0e8fdb4d146d17aa97711e3ccbd8a2e28d3cfe7fb9f23a0cf3576

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

require 'json'
require 'particlepi'

module ParticlePi
  class Settings
    attr_reader :path
    attr_reader :values
    def initialize(path = default_path)
      @path = path
      @values = {}
    end

    def load
      settings_str = IO.read(path)
      @values = JSON.parse(settings_str) unless settings_str.empty?
    rescue Errno::ENOENT
      # Ignore missing file
    end

    def save
      settings_str = JSON.pretty_generate(values)
      IO.write(path, settings_str)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
particlepi-0.1.0 lib/particlepi/settings.rb