Class: Muzak::Instance

Inherits:
Object
  • Object
show all
Includes:
Cmd, Utils
Defined in:
lib/muzak/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#album_art?, #debug, #debug?, #error, #fail_arity, #info, #music?, #output, #pretty, resolve_command, resolve_method, #verbose, #verbose?, #warn, #warn_arity

Methods included from Cmd

#_index_available?, #_index_loaded?, #_index_outdated?, #_index_sync, #_playlists_loaded?, #albums_by_artist, #clear_queue, commands, #config_get, #enqueue_album, #enqueue_artist, #enqueue_playlist, #help, #index_build, #index_load, #jukebox, #list_albums, #list_artists, #list_playlists, #list_plugins, #list_queue, #next, #now_playing, #pause, #play, #player_activate, #player_deactivate, #playlist_add_album, #playlist_add_artist, #playlist_add_current, #playlist_del_current, #playlist_delete, #playlist_shuffle, #playlists_load, #previous, #quit, #shuffle_queue, #songs_by_artist, #toggle

Constructor Details

#initialize(opts = {}) ⇒ Instance

Returns a new instance of Instance.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/muzak/instance.rb', line 17

def initialize(opts = {})
  $debug = opts[:debug]
  $verbose = opts[:verbose]

  debug "muzak is starting..."

  index_build unless _index_available?
  index_load

  @player = Player::PLAYER_MAP[Config.player].new(self)

  @plugins = initialize_plugins!

  playlists_load
  enqueue_playlist Config.autoplay if Config.autoplay
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



10
11
12
13
# File 'lib/muzak/instance.rb', line 10

def method_missing(meth, *args)
  warn "unknown command: #{Utils.resolve_method(meth)}"
  help
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/muzak/instance.rb', line 15

def config
  @config
end

#indexObject (readonly)

Returns the value of attribute index.



15
16
17
# File 'lib/muzak/instance.rb', line 15

def index
  @index
end

#playerObject (readonly)

Returns the value of attribute player.



15
16
17
# File 'lib/muzak/instance.rb', line 15

def player
  @player
end

#playlistObject (readonly)

Returns the value of attribute playlist.



15
16
17
# File 'lib/muzak/instance.rb', line 15

def playlist
  @playlist
end

Instance Method Details

#command(cmd, *args) ⇒ Object



6
7
8
# File 'lib/muzak/instance.rb', line 6

def command(cmd, *args)
  send Utils.resolve_command(cmd), *args
end

#event(type, *args) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/muzak/instance.rb', line 39

def event(type, *args)
  return unless PLUGIN_EVENTS.include?(type)

  @plugins.each do |plugin|
    Thread.new do
      plugin.send(type, *args)
    end.join
  end
end

#initialize_plugins!Object



34
35
36
37
# File 'lib/muzak/instance.rb', line 34

def initialize_plugins!
  pks = Plugin.plugin_classes.select { |pk| Config.plugin? pk.plugin_name }
  pks.map { |pk| pk.new(self) }
end