Class: Crossfader::RCFile

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/crossfader/rcfile.rb

Constant Summary collapse

FILE_NAME =
'.crossfader'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRCFile

Returns a new instance of RCFile.



9
10
11
12
# File 'lib/crossfader/rcfile.rb', line 9

def initialize
 		@path = File.join(File.expand_path('~'), FILE_NAME)
 		@data = load_file
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/crossfader/rcfile.rb', line 6

def path
  @path
end

Instance Method Details

#[]=(email, profile) ⇒ Object



21
22
23
24
25
26
# File 'lib/crossfader/rcfile.rb', line 21

def []=(email, profile)
 		configuration['email'] = profile[:email]
 		configuration['api_access_token'] = profile[:api_access_token]
 		configuration['dj_name'] = profile[:dj_name]
	write
end

#api_access_tokenObject



32
33
34
# File 'lib/crossfader/rcfile.rb', line 32

def api_access_token
	@data['configuration']['api_access_token']
end

#configurationObject



28
29
30
# File 'lib/crossfader/rcfile.rb', line 28

def configuration
 		@data['configuration']
end

#load_fileObject



14
15
16
17
18
19
# File 'lib/crossfader/rcfile.rb', line 14

def load_file
 		require 'yaml'
 		YAML.load_file(@path)
rescue Errno::ENOENT
 		default_structure
end