module Gear::Nancy::ClassMethods

Public Instance Methods

delete(*routes, &block) click to toggle source
# File lib/gear/nancy.rb, line 151
def delete(*routes, &block)  Nancy.make_camping_route('delete', routes, self, &block) end
get(*routes, &block) click to toggle source

Helper methods added to your Camping app that facilitates

# File lib/gear/nancy.rb, line 148
def get(*routes, &block)     Nancy.make_camping_route('get', routes, self, &block) end
head(*routes, &block) click to toggle source
# File lib/gear/nancy.rb, line 152
def head(*routes, &block)    Nancy.make_camping_route('head', routes, self, &block) end
patch(*routes, &block) click to toggle source
# File lib/gear/nancy.rb, line 153
def patch(*routes, &block)   Nancy.make_camping_route('patch', routes, self, &block) end
post(*routes, &block) click to toggle source
# File lib/gear/nancy.rb, line 150
def post(*routes, &block)    Nancy.make_camping_route('post', routes, self, &block) end
put(*routes, &block) click to toggle source
# File lib/gear/nancy.rb, line 149
def put(*routes, &block)     Nancy.make_camping_route('put', routes, self, &block) end
to_proc(= method(:call).to_proc) click to toggle source

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

# File lib/gear/nancy.rb, line 182
        def to_proc = method(:call).to_proc

end