Module: Gear::Nancy::ClassMethods
- Defined in:
- lib/gear/nancy.rb
Instance Method Summary collapse
- #delete(*routes, &block) ⇒ Object
-
#get(*routes, &block) ⇒ Object
Helper methods added to your Camping app that facilitates.
- #head(*routes, &block) ⇒ Object
- #link(*routes, &block) ⇒ Object
- #patch(*routes, &block) ⇒ Object
- #post(*routes, &block) ⇒ Object
- #put(*routes, &block) ⇒ Object
-
#to_proc ⇒ Object
Turns this App into a proc to be consumed by one of the block based route generators An easy way to forward requests to an app.
- #unlink(*routes, &block) ⇒ Object
Instance Method Details
#delete(*routes, &block) ⇒ Object
151 |
# File 'lib/gear/nancy.rb', line 151 def delete(*routes, &block) Nancy.make_camping_route('delete', routes, self, &block) end |
#get(*routes, &block) ⇒ Object
Helper methods added to your Camping app that facilitates
148 |
# File 'lib/gear/nancy.rb', line 148 def get(*routes, &block) Nancy.make_camping_route('get', routes, self, &block) end |
#head(*routes, &block) ⇒ Object
152 |
# File 'lib/gear/nancy.rb', line 152 def head(*routes, &block) Nancy.make_camping_route('head', routes, self, &block) end |
#link(*routes, &block) ⇒ Object
154 |
# File 'lib/gear/nancy.rb', line 154 def link(*routes, &block) Nancy.make_camping_route('link', routes, self, &block) end |
#patch(*routes, &block) ⇒ Object
153 |
# File 'lib/gear/nancy.rb', line 153 def patch(*routes, &block) Nancy.make_camping_route('patch', routes, self, &block) end |
#post(*routes, &block) ⇒ Object
150 |
# File 'lib/gear/nancy.rb', line 150 def post(*routes, &block) Nancy.make_camping_route('post', routes, self, &block) end |
#put(*routes, &block) ⇒ Object
149 |
# File 'lib/gear/nancy.rb', line 149 def put(*routes, &block) Nancy.make_camping_route('put', routes, self, &block) end |
#to_proc ⇒ Object
Turns this App into a proc to be consumed by one of the block based route generators An easy way to forward requests to an app. a references self, that’s then captured by the proc, which is a closure. because it’s a closure, and because it captures self, we can then call this proc anywhere we want.
The syntax: ‘a` is an implicit call to the `#call` method. the brackets are syntatic sugar to get this to work. The following code is equivalent:
e = [] # given e is a rack array.
a.call(e)
a.(e)
a[e]
This code is defined in the Nancy Camping Gear. Specifically in it’s ClassMethods module. ClassMethods is then extended onto our Camping app, Giving it the appearance of being a method of the module. In our cases Our modules are our Apps. The code:
def to_proc = method(:call).to_proc
First gets a ‘Method` object from the app, then converts it to a proc. In our case we just want call, so this makes the whole api pretty simple. def to_proc = method(:call).to_proc
182 |
# File 'lib/gear/nancy.rb', line 182 def to_proc = method(:call).to_proc |
#unlink(*routes, &block) ⇒ Object
155 |
# File 'lib/gear/nancy.rb', line 155 def unlink(*routes, &block) Nancy.make_camping_route('unlink', routes, self, &block) end |