module Gopher

Constants

VERSION

Public Class Methods

app(&block) click to toggle source
# File lib/gopher.rb, line 279
def app(&block)
  @app = Application.new(&block)
end
Also aliased as: application
application(&block)
Alias for: app
determine_type(selector) click to toggle source
# File lib/gopher.rb, line 243
def self.determine_type(selector)
  case File.extname(selector).downcase
  when '.jpg', '.png' then 'I'
  when '.mp3' then 's'
  when '.gif' then 'g'
  else '0'
  end
end
reload(*files) click to toggle source
# File lib/gopher.rb, line 284
def reload(*files)
  @last_reload = Time.now
  @reloadables = files
end
reloadables() click to toggle source
# File lib/gopher.rb, line 289
def reloadables
  @reloadables ||= []
end
run() click to toggle source
# File lib/gopher.rb, line 293
def run
  return if EM.reactor_running?
  EM.run do
    EM.start_server(@app.bindto, @app.port, Gopher::Connection) do |c|
      c.app = @app
      reloadables.each do |f|
        load f if File.mtime(f) > @last_reload
      end
      @last_reload = Time.now
    end        
  end
end
sanitize_selector(selector) click to toggle source
# File lib/gopher.rb, line 236
def self.sanitize_selector(selector)
  selector = selector.dup
  selector.strip!
  selector.gsub!(/\.+/, '.')
  selector
end
stop() click to toggle source
# File lib/gopher.rb, line 306
def stop
  return unless EM.reactor_running?
  EM.stop_server
end