Module: Gopher

Defined in:
lib/gopher.rb,
lib/gopher/redirect.rb

Defined Under Namespace

Modules: Redirect Classes: Application, Connection, DirectoryHandler, DirectoryNotFound, GopherError, Handler, InvalidRequest, MapContext, MapHandler, NotFound, TextContext, TextHandler

Constant Summary collapse

VERSION =
'0.7.1'

Class Method Summary collapse

Class Method Details

.app(&block) ⇒ Object Also known as: application



279
280
281
# File 'lib/gopher.rb', line 279

def app(&block)
  @app = Application.new(&block)
end

.determine_type(selector) ⇒ Object



243
244
245
246
247
248
249
250
# 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) ⇒ Object



284
285
286
287
# File 'lib/gopher.rb', line 284

def reload(*files)
  @last_reload = Time.now
  @reloadables = files
end

.reloadablesObject



289
290
291
# File 'lib/gopher.rb', line 289

def reloadables
  @reloadables ||= []
end

.runObject



293
294
295
296
297
298
299
300
301
302
303
304
# 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) ⇒ Object



236
237
238
239
240
241
# File 'lib/gopher.rb', line 236

def self.sanitize_selector(selector)
  selector = selector.dup
  selector.strip!
  selector.gsub!(/\.+/, '.')
  selector
end

.stopObject



306
307
308
309
# File 'lib/gopher.rb', line 306

def stop
  return unless EM.reactor_running?
  EM.stop_server
end