Class: Gopher::DirectoryHandler
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#index ⇒ Object
Returns the value of attribute index.
-
#selector ⇒ Object
Returns the value of attribute selector.
Attributes inherited from Handler
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(path, selector = '') ⇒ DirectoryHandler
constructor
A new instance of DirectoryHandler.
- #to_map ⇒ Object
Methods inherited from Handler
Constructor Details
#initialize(path, selector = '') ⇒ DirectoryHandler
Returns a new instance of DirectoryHandler.
118 119 120 121 122 123 |
# File 'lib/gopher.rb', line 118 def initialize(path, selector = '') raise DirectoryNotFound unless File.directory? path @selector = selector @base = File.(path) @index = YAML.load_file(index_file) if File.exist?(index_file) end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
116 117 118 |
# File 'lib/gopher.rb', line 116 def base @base end |
#index ⇒ Object
Returns the value of attribute index.
116 117 118 |
# File 'lib/gopher.rb', line 116 def index @index end |
#selector ⇒ Object
Returns the value of attribute selector.
116 117 118 |
# File 'lib/gopher.rb', line 116 def selector @selector end |
Instance Method Details
#call(*args) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gopher.rb', line 125 def call(*args) path = File.join(base, *args) if File.directory? path return DirectoryHandler.new(path, File.join(selector, args)).with(application).to_map elsif File.file? path return File.open(path) else raise NotFound end end |
#to_map ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gopher.rb', line 136 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 |