Class: Radiodan

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/radiodan/middleware/touch_file.rb,
lib/radiodan.rb,
lib/radiodan/track.rb,
lib/radiodan/player.rb,
lib/radiodan/builder.rb,
lib/radiodan/logging.rb,
lib/radiodan/version.rb,
lib/radiodan/playlist.rb,
lib/radiodan/adapter/mpd.rb,
lib/radiodan/event_binding.rb,
lib/radiodan/playlist_sync.rb,
lib/radiodan/middleware/panic.rb,
lib/radiodan/adapter/mpd/response.rb,
lib/radiodan/middleware/web_server.rb,
lib/radiodan/adapter/mpd/connection.rb,
lib/radiodan/middleware/toggle_playlist.rb,
lib/radiodan/adapter/mpd/playlist_parser.rb,
lib/radiodan/middleware/playlist_to_start.rb

Overview

Controls the radio by touching files.

This class looks for matching files in a given directory. When the file exists, the corresponding event is triggered and the file deleted.

Defined Under Namespace

Modules: EventBinding, Logging Classes: Builder, MPD, Panic, Player, Playlist, PlaylistSync, PlaylistToStart, Sinatra, TogglePlaylist, TouchFile, Track, WebServer

Constant Summary collapse

VERSION =
"1.0.1"

Instance Method Summary collapse

Methods included from Logging

included, level, level=, #logger, output, output=

Constructor Details

#initialize(&blk) ⇒ Radiodan

Returns a new instance of Radiodan.



14
15
16
# File 'lib/radiodan.rb', line 14

def initialize(&blk)
  @builder = Builder.new(&blk)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



49
50
51
52
53
54
55
# File 'lib/radiodan.rb', line 49

def method_missing(method, *args, &block)
  if player.respond_to? method
    player.send method, *args, &block
  else
    super
  end
end

Instance Method Details

#playerObject



35
36
37
# File 'lib/radiodan.rb', line 35

def player
  @builder.player
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/radiodan.rb', line 39

def respond_to?(method)
  if player.respond_to? method
    true
  else
    super
  end
end

#startObject



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

def start
  # keep player running on schedule
  raise "no player set" unless player.adapter?
  
  stop_player_on_exit
  
  EM.synchrony do
    trap_signals!
    EventMachine::Synchrony.next_tick { @builder.call_middleware! }
    
    EM::Synchrony.add_periodic_timer(1) do
      logger.info "SYNC!"
      player.sync if player
    end
  end
end