class Gopher::DirectoryHandler
Attributes
base[RW]
index[RW]
selector[RW]
Public Class Methods
new(path, selector = '')
click to toggle source
# File lib/gopher.rb, line 121 def initialize(path, selector = '') raise DirectoryNotFound unless File.directory? path @selector = selector @base = File.expand_path(path) @index = YAML.load_file(index_file) if File.exist?(index_file) end
Public Instance Methods
call(*args)
click to toggle source
# File lib/gopher.rb, line 128 def call(*args) path = File.join(base, *args) if File.directory? path DirectoryHandler.new(path, File.join(selector, args)).with(app).to_map elsif File.file? path File.open(path) else raise NotFound end end
to_map()
click to toggle source
# File lib/gopher.rb, line 139 def to_map MapContext.with_block(host, port, self) do |handler| if handler.index paragraph handler.index['description'] handler.index['entries'].each do |txt, path| link txt, File.join(handler.selector, path) end else Dir["#{handler.base}/*"].each do |path| basename = File.basename(path) if File.directory? path map basename, File.join(handler.selector, basename) else link basename, File.join(handler.selector, basename) end end end text Time.now end end
Private Instance Methods
index_file()
click to toggle source
# File lib/gopher.rb, line 161 def index_file File.join(base, '.gopher') end