class CompanionApi::Profile

Attributes

file[RW]
profile_name[RW]
settings[RW]

Public Class Methods

new(profile_name) click to toggle source
# File lib/companion_api/profile.rb, line 7
def initialize(profile_name)
  @file = File.join(CompanionApi.config.profile_directory, "#{profile_name}.json")
  FileUtils.mkdir_p(File.dirname(@file)) unless File.exist?(File.dirname(@file))
  @settings = {}

  load
end

Public Instance Methods

get(key) click to toggle source
# File lib/companion_api/profile.rb, line 20
def get(key)
  @settings[key.to_sym]
end
set(key, value) click to toggle source
# File lib/companion_api/profile.rb, line 15
def set(key, value)
  @settings[key.to_sym] = value
  save!
end

Protected Instance Methods

load() click to toggle source
# File lib/companion_api/profile.rb, line 26
def load
  return save! unless File.exist?(@file)

  @settings = JSON.parse(open(@file).read, symbolize_names: true)
end
save!() click to toggle source
# File lib/companion_api/profile.rb, line 32
def save!
  File.open(@file, 'w') do |f|
    f.write(@settings.to_json)
  end
end