Class: Muzak::Instance
- Inherits:
-
Object
- Object
- Muzak::Instance
- Defined in:
- lib/muzak/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#playlist ⇒ Object
readonly
Returns the value of attribute playlist.
Instance Method Summary collapse
- #command(cmd, *args) ⇒ Object
- #event(type, *args) ⇒ Object
-
#initialize(opts = {}) ⇒ Instance
constructor
A new instance of Instance.
- #initialize_plugins! ⇒ Object
- #method_missing(meth, *args) ⇒ Object
Methods included from Utils
#album_art?, #debug, #debug?, #error, #fail_arity, #info, #music?, #output, #pretty, #verbose, #verbose?, #warn, #warn_arity
Methods included from Cmd
#_config_available?, #_config_init, #_config_loaded?, #_config_plugin?, #_config_sync, #_index_available?, #_index_loaded?, #_index_outdated?, #_index_sync, #_playlist_loaded?, #albums_by_artist, #clear_queue, commands, #config_get, #config_load, #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_load, #playlist_shuffle, #previous, #quit, resolve_command, resolve_method, #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 33 34 35 |
# File 'lib/muzak/instance.rb', line 17 def initialize(opts = {}) $debug = opts[:debug] $verbose = opts[:verbose] debug "muzak is starting..." _config_init unless _config_available? config_load index_build unless _index_available? index_load @player = Player::PLAYER_MAP[@config["player"]].new(self) @plugins = initialize_plugins! playlist_load @config["default-playlist"] if @config["default-playlist"] enqueue_playlist if _playlist_loaded? && @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: #{Cmd.resolve_method(meth)}" help end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/muzak/instance.rb', line 15 def config @config end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
15 16 17 |
# File 'lib/muzak/instance.rb', line 15 def index @index end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
15 16 17 |
# File 'lib/muzak/instance.rb', line 15 def player @player end |
#playlist ⇒ Object (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 Cmd.resolve_command(cmd), *args end |
#event(type, *args) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/muzak/instance.rb', line 42 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
37 38 39 40 |
# File 'lib/muzak/instance.rb', line 37 def initialize_plugins! pks = Plugin.plugin_classes.select { |pk| _config_plugin? pk.plugin_name } pks.map { |pk| pk.new(self) } end |