Class: CompanionApi::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/companion_api/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_name) ⇒ Profile

Returns a new instance of Profile.



7
8
9
10
11
12
13
# 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

Instance Attribute Details

#fileObject

Returns the value of attribute file.



4
5
6
# File 'lib/companion_api/profile.rb', line 4

def file
  @file
end

#profile_nameObject

Returns the value of attribute profile_name.



3
4
5
# File 'lib/companion_api/profile.rb', line 3

def profile_name
  @profile_name
end

#settingsObject

Returns the value of attribute settings.



5
6
7
# File 'lib/companion_api/profile.rb', line 5

def settings
  @settings
end

Instance Method Details

#get(key) ⇒ Object



20
21
22
# File 'lib/companion_api/profile.rb', line 20

def get(key)
  @settings[key.to_sym]
end

#set(key, value) ⇒ Object



15
16
17
18
# File 'lib/companion_api/profile.rb', line 15

def set(key, value)
  @settings[key.to_sym] = value
  save!
end