]> git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/source_manager.rb
First Batch of Source Changes [Broken]
[rbdr/lyricli.rb] / lib / source_manager.rb
1 module Lyricli
2 class SourceManager
3
4 include Lyricli::Util
5
6 def initialize
7 @enabled_sources = []
8 @config = Lyricli::Config
9 end
10
11 def enable(source_name)
12 if source_module = module_exists?(camelize(str))
13 source_module.enable
14 @config[:enabled_sources] << klass.name
15 else
16 raise Lyricli::EnableSourceException
17 end
18 end
19
20 def disable(source_name)
21 if source_module = module_exists?(camelize(str))
22 @config[:enabled_sources].delete(klass.name)
23 else
24 raise Lyricli::DisableSourceException
25 end
26 end
27
28 def reset(source_name)
29 if source_module = module_exists?(camelize(str))
30 source_module.reset
31 disable(source_name)
32 else
33 raise Lyricli::ResetSourceException
34 end
35 end
36
37 def start
38 @config[:enabled_sources].each do |source|
39 begin
40 source.start
41 rescue
42 fail "Source #{source.name} has failed to start. Please reset the source by running `#{$0} source reset #{source.name}.`"
43 end
44 end
45 end
46 end
47 end