Sha256: 22a6cc199b69802cdcec8cd878e3153e9960347bc22173cdefb0e0bc263519b5

Contents?: true

Size: 641 Bytes

Versions: 2

Compression:

Stored size: 641 Bytes

Contents

=begin
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.
=end

class Radiodan
class TouchFile
  include Logging  
  def initialize(config)
    @path = config[:dir]
  end

  def call(player)
    EM::Synchrony.now_and_every(0.5) do
      player.events.each do |event|
        file = event.to_s
        p = Pathname.new(File.join(@path, file))
        if p.exist?
          logger.debug "Responding to file #{file}"
          p.delete
          player.trigger_event file
        end
      end
    end
  end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
radiodan-1.0.1 lib/radiodan/middleware/touch_file.rb
radiodan-1.0.0 lib/radiodan/middleware/touch_file.rb