X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/blobdiff_plain/823e558b5cd2ec219d0fc7226c54f2ee7ad807d2..7b40d722ef984b45528010ef27a271349e798c09:/doc/Lyricli/Configuration.html diff --git a/doc/Lyricli/Configuration.html b/doc/Lyricli/Configuration.html index 7ca3571..54b439c 100644 --- a/doc/Lyricli/Configuration.html +++ b/doc/Lyricli/Configuration.html @@ -6,7 +6,7 @@ Class: Lyricli::Configuration - — Documentation by YARD 0.8.1 + — Documentation by YARD 0.8.2.1 @@ -99,7 +99,19 @@
+

Overview

+
+

+This class handles the configuration of Lyricli +

+ + +
+
+
+ +

Constant Summary

@@ -143,7 +155,10 @@ -
+

+Ensure this is only called once. +

+
@@ -160,7 +175,7 @@
  • - - (Object) [](key) + - (String, ...) [](key) @@ -174,7 +189,10 @@ -
    +

    +Access configuration properties, loads config if needed beforehand. +

    +
  • @@ -196,7 +214,37 @@ -
    +

    +Assigns a new value to a configuration key, loads config if needed and +saves it after updating. +

    +
    + + + + +
  • + + + - (Object) delete(key) + + + + + + + + + + + + + +

    +Deletes a key from the configuration, loads config if needed and saves it +after deleting. +

    +
  • @@ -221,7 +269,58 @@

    -A new instance of Configuration. +Defines the paths to the default and user configuration files. +

    +
    + + + + +
  • + + + - (Object) load_config + + + + + + + + + + + + + +

    +Loads the configuration from the user file, attempts to create it from +defaults if it’s not present. +

    +
    + +
  • + + +
  • + + + - (Object) save_config + + + + + + + + + + + + + +

    +Serializes the `@config` Hash to JSON and saves it to a file.

    @@ -246,7 +345,7 @@ A new instance of Configuration.

    -A new instance of Configuration +Defines the paths to the default and user configuration files

    @@ -261,17 +360,19 @@ A new instance of Configuration
     
     
    -4
    -5
    -6
    -7
    +7 +8 +9 +10 +11 -
    # File 'lib/lyricli/configuration.rb', line 4
    +      
    # File 'lib/lyricli/configuration.rb', line 7
     
     def initialize
       @config_path = "~/.lyricli.conf"
       @defaults_path = "defaults.json"
    +  @config = nil
     end
    @@ -294,18 +395,31 @@ A new instance of Configuration - +
    +
    +

    +Ensure this is only called once. Only use the instance class variable to +access this method, as its constructor is private. +

    + + +
    +
    +
    + + +
     
     
    -11
    -12
    -13
    +17 +18 +19
    -
    # File 'lib/lyricli/configuration.rb', line 11
    +      
    # File 'lib/lyricli/configuration.rb', line 17
     
     def self.instance
       @@instance
    @@ -324,25 +438,77 @@ A new instance of Configuration
           

    - - (Object) [](key) + - (String, ...) [](key) + + + + +

    +
    +

    +Access configuration properties, loads config if needed beforehand. +

    + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + key + + + (String) + + + + — +

      +the configuration key to access +

      +
      + +
    • +
    +

    Returns:

    +
      - +
    • + + + (String, Hash, Array) + + + + — +

      +the value of the configuration key. +

      +
      + +
    • + + + +
       
       
      -15
      -16
      -17
      -18
      +25 +26 +27 +28
      -
      # File 'lib/lyricli/configuration.rb', line 15
      +      
      # File 'lib/lyricli/configuration.rb', line 25
       
       def [](key)
         load_config unless @config
      @@ -362,20 +528,72 @@ A new instance of Configuration
         
       
         
      -
      +
      +
      +

      +Assigns a new value to a configuration key, loads config if needed and +saves it after updating. +

      + + +
      +
      +
      +

      Parameters:

      +
        + +
      • + + key + + + (String) + + + + — +

        +the configuration key to set +

        +
        + +
      • + +
      • + + value + + + (Object) + + + + — +

        +the value for the configuration key, can be any object as long as it can be +converted to JSON +

        +
        + +
      • + +
      + + +
       
       
      -20
      -21
      -22
      -23
      -24
      +36 +37 +38 +39 +40
      -
      # File 'lib/lyricli/configuration.rb', line 20
      +      
      # File 'lib/lyricli/configuration.rb', line 36
       
       def []=(key, value)
         load_config unless @config
      @@ -385,6 +603,179 @@ A new instance of Configuration
           
      + + +
      +

      + + - (Object) delete(key) + + + + + +

      +
      +

      +Deletes a key from the configuration, loads config if needed and saves it +after deleting. +

      + + +
      +
      +
      +

      Parameters:

      +
        + +
      • + + key + + + (String) + + + + — +

        +the key to delete +

        +
        + +
      • + +
      + + +
      + + + + +
      +
      +
      +
      +46
      +47
      +48
      +49
      +50
      +
      +
      # File 'lib/lyricli/configuration.rb', line 46
      +
      +def delete(key)
      +  load_config unless @config
      +  @config.delete(key)
      +  save_config
      +end
      +
      +
      + +
      +

      + + - (Object) load_config + + + + + +

      +
      +

      +Loads the configuration from the user file, attempts to create it from +defaults if it’s not present. sets the `@config` instance variable. +

      + + +
      +
      +
      + + +
      + + + + +
      +
      +
      +
      +56
      +57
      +58
      +59
      +60
      +61
      +62
      +63
      +64
      +65
      +
      +
      # File 'lib/lyricli/configuration.rb', line 56
      +
      +def load_config
      +  path = File.expand_path(@config_path)
      +
      +  if File.exists?(path)
      +    file = File.new(path, "r")
      +    @config = MultiJson.decode(file.read)
      +  else
      +    load_default_config
      +  end
      +end
      +
      +
      + +
      +

      + + - (Object) save_config + + + + + +

      +
      +

      +Serializes the `@config` Hash to JSON and saves it to a file. +

      + + +
      +
      +
      + + +
      + + + + +
      +
      +
      +
      +68
      +69
      +70
      +71
      +72
      +73
      +
      +
      # File 'lib/lyricli/configuration.rb', line 68
      +
      +def save_config
      +  path = File.expand_path(@config_path)
      +  file = File.new(path, "w")
      +  file.print(MultiJson.encode(@config))
      +  file.close
      +end
      +
      @@ -392,9 +783,9 @@ A new instance of Configuration