Class: Muzak::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/muzak/config.rb

Overview

Muzak's static configuration dumping ground. Key-value pairs are loaded from CONFIG_FILE and translated from kebab-case to snake_case methods.

Examples:

# corresponds to `art-geometry: 300x300` in configuration
Config.art_geometry # => "300x300"

See Also:

Constant Summary collapse

CONFIG_DIR =

The root directory for all user configuration, data, etc

File.expand_path("~/.config/muzak").freeze
CONFIG_FILE =

Muzak's primary configuration file

See Also:

File.join(CONFIG_DIR, "muzak.yml").freeze
INDEX_FILE =

Muzak's music index

File.join(CONFIG_DIR, "index.dat").freeze
PLAYLIST_DIR =

The directory for all user playlists

File.join(CONFIG_DIR, "playlists").freeze
PLAYLIST_GLOB =

The glob pattern for all user playlists

File.join(PLAYLIST_DIR, "*.yml").freeze
USER_PLUGIN_DIR =

The directory for all user plugins

File.join(CONFIG_DIR, "plugins").freeze
USER_COMMAND_DIR =

The directory for all user commands

File.join(CONFIG_DIR, "commands").freeze
USER_COMMAND_GLOB =

The glob pattern for all user commands

File.join(USER_COMMAND_DIR, "*.rb").freeze
MUSIC_SUFFIXES =

All filename suffixes that muzak recognizes as music.

[
  ".mp3",
  ".flac",
  ".m4a",
  ".wav",
  ".ogg",
  ".oga",
  ".opus",
].freeze
ALBUM_ART_REGEX =

The regular expression that muzak uses to find album art.

/(cover)|(folder).(jpg)|(png)/i
PLUGIN_EVENTS =

All events currently propagated by Instance#event

%i[
  instance_started
  instance_quitting
  player_activated
  player_deactivated
  song_loaded
  song_unloaded
  playlist_enqueued
].freeze
DEFAULT_CONFIG =

The default configuration keys and values.

{
  # core defaults
  "events" => true,
  "debug" => false,
  "verbose" => true,
  "music" => File.expand_path("~/music"),
  "player" => "mpv",
  "jukebox-size" => 100,
  "autoplay" => false,

  # client/daemon defaults
  "daemon-port" => 2669,
  "daemon-host" => "localhost",
}.freeze

Class Method Summary collapse

Class Method Details

.method_missing(method, *args) ⇒ false

Catches all undefined configuration keys and defaults them to false.

Returns:

  • (false)

101
102
103
104
105
106
107
108
109
# File 'lib/muzak/config.rb', line 101

def self.method_missing(method, *args)
  # this is basically useless, since respond_to_missing? will always be true,
  # but it gets RuboCop to shut up.
  if respond_to_missing? method, *args
    false
  else
    super
  end
end

.plugin?(pname) ⇒ Boolean

Note:

the truth-value of this method is used in part to determine which plugins should be loaded.

Returns whether or not the given plugin is configured.

Returns:

  • (Boolean)

    whether or not the given plugin is configured


120
121
122
# File 'lib/muzak/config.rb', line 120

def self.plugin?(pname)
  respond_to? "plugin_#{pname}"
end

.resolve_command(cmd) ⇒ String

Convert the given command into a method (kebab to camel case).

Examples:

resolve_command "do-something" # => "do_something"

Parameters:

  • cmd (String)

    the command to convert

Returns:

  • (String)

    the method corresponding to the command


86
87
88
# File 'lib/muzak/config.rb', line 86

def self.resolve_command(cmd)
  cmd.tr "-", "_"
end

.resolve_method(meth) ⇒ String

Convert the given method into a command (camel to kebab case).

Examples:

resolve_method "do_something" # => "do-something"

Parameters:

  • meth (String, Symbol)

    the method to convert

Returns:

  • (String)

    the command corresponding to the method


95
96
97
# File 'lib/muzak/config.rb', line 95

def self.resolve_method(meth)
  meth.to_s.tr "_", "-"
end

.respond_to_missing?(*_args) ⇒ true

We "respond" to all methods with a default of false, so this is always true.

Returns:

  • (true)

113
114
115
# File 'lib/muzak/config.rb', line 113

def self.respond_to_missing?(*_args)
  true
end