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.5.1'

Class Method Summary collapse

Class Method Details

.application(&block) ⇒ Object



273
274
275
# File 'lib/gopher.rb', line 273

def self.application(&block)
  @application = Application.new(&block)
end

.determine_type(selector) ⇒ Object



239
240
241
242
243
244
245
# File 'lib/gopher.rb', line 239

def self.determine_type(selector)
  case File.extname(selector).downcase
  when '.jpg', '.png' then 'I'
  when '.mp3' then 's'
  else '0'
  end
end

.reload(*files) ⇒ Object



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

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

.reloadablesObject



282
283
284
# File 'lib/gopher.rb', line 282

def self.reloadables
  @reloadables ||= []
end

.runObject



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/gopher.rb', line 286

def self.run
  return if EM.reactor_running?
  EM.run do
    EM.start_server(@application.host, @application.port, Gopher::Connection) do |c|
      c.application = @application
      reloadables.each do |f|
        load f if File.mtime(f) > @last_reload
      end
      @last_reload = Time.now
    end        
  end
end

.sanitize_selector(selector) ⇒ Object



233
234
235
236
237
238
# File 'lib/gopher.rb', line 233

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