Class: Gopher::Application
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
-
#selectors ⇒ Object
Returns the value of attribute selectors.
Instance Method Summary collapse
- #add_handler(selector, handler) ⇒ Object
- #application(selector, handler) ⇒ Object
- #helpers(&block) ⇒ Object
-
#initialize(&block) ⇒ Application
constructor
A new instance of Application.
- #lookup(selector) ⇒ Object
- #map(selector, &block) ⇒ Object
- #mount(selector, path) ⇒ Object
- #reload(*f) ⇒ Object
- #request(selector) ⇒ Object
- #text(selector, &block) ⇒ Object
- #use(mod) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Application
Returns a new instance of Application.
17 18 19 20 |
# File 'lib/gopher.rb', line 17 def initialize(&block) reset! self.instance_eval(&block) end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
15 16 17 |
# File 'lib/gopher.rb', line 15 def root @root end |
#selectors ⇒ Object
Returns the value of attribute selectors.
15 16 17 |
# File 'lib/gopher.rb', line 15 def selectors @selectors end |
Instance Method Details
#add_handler(selector, handler) ⇒ Object
61 62 63 64 65 |
# File 'lib/gopher.rb', line 61 def add_handler(selector, handler) selector = Gopher.sanitize_selector(selector) selector.sub!(/^\/*/, '') selectors[/^\/?#{selector}$/] = handler end |
#application(selector, handler) ⇒ Object
45 46 47 |
# File 'lib/gopher.rb', line 45 def application(selector, handler) add_handler selector, handler end |
#helpers(&block) ⇒ Object
40 41 42 43 |
# File 'lib/gopher.rb', line 40 def helpers(&block) MapContext.class_eval(&block) TextContext.class_eval(&block) end |
#lookup(selector) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/gopher.rb', line 54 def lookup(selector) selectors.find do |k, v| return v, *$~[1..-1] if k =~ Gopher.sanitize_selector(selector) end raise NotFound end |
#map(selector, &block) ⇒ Object
32 33 34 |
# File 'lib/gopher.rb', line 32 def map(selector, &block) add_handler selector.gsub(/:(.+)/, '(.+)'), MapHandler.new(&block).with(self) end |
#mount(selector, path) ⇒ Object
28 29 30 |
# File 'lib/gopher.rb', line 28 def mount(selector, path) add_handler "#{selector}/?(.*)", DirectoryHandler.new(path, selector).with(self) end |
#reload(*f) ⇒ Object
22 |
# File 'lib/gopher.rb', line 22 def reload(*f); Gopher.reload(*f) end |
#request(selector) ⇒ Object
49 50 51 52 |
# File 'lib/gopher.rb', line 49 def request(selector) handler, *args = lookup(selector) handler.call(*args) end |
#text(selector, &block) ⇒ Object
36 37 38 |
# File 'lib/gopher.rb', line 36 def text(selector, &block) add_handler selector.gsub(/:(.+)/, '(.+)'), TextHandler.new(&block).with(self) end |
#use(mod) ⇒ Object
24 25 26 |
# File 'lib/gopher.rb', line 24 def use(mod) extend(mod) end |