X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/blobdiff_plain/ad84791b951f4ebdfae9c6bf0a54244a8b5c8f16..34d0bf15a6f4009de376ceed1d7d5cca24a8dfe7:/doc/Lyricli/SourceManager.html?ds=inline diff --git a/doc/Lyricli/SourceManager.html b/doc/Lyricli/SourceManager.html index 399b337..2f48f97 100644 --- a/doc/Lyricli/SourceManager.html +++ b/doc/Lyricli/SourceManager.html @@ -6,7 +6,7 @@ Class: Lyricli::SourceManager - — Documentation by YARD 0.8.1 + — Documentation by YARD 0.8.2.1 @@ -121,6 +121,28 @@
  • + - (Object) available_sources(format = false) + + + + + + + + + + + + + +
    + +
  • + + +
  • + + - (Object) current_track @@ -179,6 +201,28 @@ +
    + +
  • + + +
  • + + + - (Object) format_sources(sources) + + + + + + + + + + + + +
  • @@ -318,7 +362,65 @@ A new instance of SourceManager
    -

    +

    + + - (Object) available_sources(format = false) + + + + + +

    + + + + +
    +
    +
    +
    +81
    +82
    +83
    +84
    +85
    +86
    +87
    +88
    +89
    +90
    +91
    +92
    +93
    +94
    +95
    +96
    +97
    +
    +
    # File 'lib/lyricli/source_manager.rb', line 81
    +
    +def available_sources(format = false)
    +  path_root = File.expand_path(File.dirname(__FILE__))
    +  sources = Dir[path_root+"/sources/*.rb"].map{ |s|
    +    name = s.split("/").last.gsub(/\.rb/, "")
    +
    +    # Add a star to denote enabled sources
    +    name
    +  }
    +
    +  # Remove arguments (Hack?) We don't want anybody to touch tihs one.
    +  sources.delete("arguments")
    +  if format
    +    format_sources(sources)
    +  else
    +    sources
    +  end
    +end
    +
    +
    + +
    +

    - (Object) current_track @@ -332,28 +434,46 @@ A new instance of SourceManager
     
     
    -46
    -47
    -48
    -49
    -50
    -51
    -52
    -53
    -54
    -55
    -56
    +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 -
    # File 'lib/lyricli/source_manager.rb', line 46
    +      
    # File 'lib/lyricli/source_manager.rb', line 60
     
     def current_track
       track = nil
    +  lock = false
       @enabled_sources.each do |source|
         begin
    -      track ||= source.current_track
    +      current_track = source.current_track
    +
    +      # This is a special thing for arguments. The thing is, they need to
    +      # be inputted manually. So, if they are present they won't allow
    +      # anyone else to give results. Makes sense, yet a bit hacky.
    +      unless current_track[:artist].nil? || current_track[:artist].empty? || current_track[:song].nil? || current_track[:song].empty?
    +        track = current_track unless lock
    +        lock = true if source.class.name == "arguments"
    +      end
         rescue
    -      fail "Source #{source.name} has failed to start. Please reset the source by running `#{$0} source reset #{source.name}.`"
    +      raise SourceConfigurationException
         end
       end
       track
    @@ -378,22 +498,32 @@ A new instance of SourceManager
           
     
     
    -29
    -30
    -31
    -32
    -33
     34
    -35
    +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45
    -
    # File 'lib/lyricli/source_manager.rb', line 29
    +      
    # File 'lib/lyricli/source_manager.rb', line 34
     
     def disable(source_name)
    -  if klass = parse_class(camelize(source_name))
    -    @config["enabled_sources"].delete(klass.name)
    +  if available_sources.include?(source_name)
    +    if klass = parse_class(camelize(source_name))
    +      @config["enabled_sources"].delete(klass.name)
    +      @config.save_config
    +    else
    +      raise DisableSourceException
    +    end
       else
    -    raise DisableSourceException
    +    raise UnknownSource
       end
     end
    @@ -424,23 +554,69 @@ A new instance of SourceManager 24 25 26 -27
    +27 +28 +29 +30 +31 +32
    # 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!
    +  if available_sources.include?(source_name)
    +    if klass = parse_class(camelize(source_name))
    +      klass.enable
    +      @config["enabled_sources"] << klass.name
    +      @config["enabled_sources"].uniq!
    +      @config.save_config
    +    else
    +      raise EnableSourceException
    +    end
       else
    -    raise EnableSourceException
    +    raise UnknownSource
       end
     end
    +

    + +
    +

    + + - (Object) format_sources(sources) + + + + + +

    + + + + +
    +
    +
    +
    +99
    +100
    +101
    +102
    +103
    +104
    +
    +
    # File 'lib/lyricli/source_manager.rb', line 99
    +
    +def format_sources(sources)
    +  sources.map{ |s|
    +    s << "*" if @config["enabled_sources"].include?(s)
    +    s
    +  }
    +end
    +
    @@ -458,24 +634,32 @@ A new instance of SourceManager
     
     
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 -
    # File 'lib/lyricli/source_manager.rb', line 37
    +      
    # File 'lib/lyricli/source_manager.rb', line 47
     
     def reset(source_name)
    -  if klass = parse_class(camelize(source_name))
    -    klass.reset
    -    disable(source_name)
    +  if available_sources.include?(source_name)
    +    if klass = parse_class(camelize(source_name))
    +      klass.reset
    +      disable(source_name)
    +    else
    +      raise ResetSourceException
    +    end
       else
    -    raise ResetSourceException
    +    raise UnknownSource
       end
     end
    @@ -488,9 +672,9 @@ A new instance of SourceManager