Class: Lyricli::SourceManager
- Inherits:
-
Object
- Object
- Lyricli::SourceManager
show all
- Includes:
- Util
- Defined in:
- lib/lyricli/source_manager.rb
Instance Method Summary
(collapse)
Methods included from Util
#camelize, #parse_class, #sanitize_param
Constructor Details
A new instance of SourceManager
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/lyricli/source_manager.rb', line 6
def initialize
@enabled_sources = []
@config = Configuration.instance
@config["enabled_sources"].each do |source|
if klass = parse_class(camelize(source))
current_source = klass.new
@enabled_sources << current_source
else
raise StartSourceException
end
end
end
|
Instance Method Details
- (Object) current_track
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/lyricli/source_manager.rb', line 46
def current_track
track = nil
@enabled_sources.each do |source|
begin
track ||= source.current_track
rescue
fail "Source #{source.name} has failed to start. Please reset the source by running `#{$0} source reset #{source.name}.`"
end
end
track
end
|
- (Object) disable(source_name)
29
30
31
32
33
34
35
|
# File 'lib/lyricli/source_manager.rb', line 29
def disable(source_name)
if klass = parse_class(camelize(source_name))
@config["enabled_sources"].delete(klass.name)
else
raise DisableSourceException
end
end
|
- (Object) enable(source_name)
19
20
21
22
23
24
25
26
27
|
# File 'lib/lyricli/source_manager.rb', line 19
def enable(source_name)
if klass = parse_class(camelize(source_name))
klass.enable
@config["enabled_sources"] << klass.name
@config["enabled_sources"].uniq!
else
raise EnableSourceException
end
end
|
- (Object) reset(source_name)
37
38
39
40
41
42
43
44
|
# File 'lib/lyricli/source_manager.rb', line 37
def reset(source_name)
if klass = parse_class(camelize(source_name))
klass.reset
disable(source_name)
else
raise ResetSourceException
end
end
|