Module: Gear::Nancy::ClassMethods

Defined in:
lib/camping/gear/nancy.rb

Instance Method Summary collapse

Instance Method Details

#delete(*routes, &block) ⇒ Object



133
# File 'lib/camping/gear/nancy.rb', line 133

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



130
# File 'lib/camping/gear/nancy.rb', line 130

def get(*routes, &block)     Nancy.make_camping_route('get', routes, self, &block) end

#head(*routes, &block) ⇒ Object



134
# File 'lib/camping/gear/nancy.rb', line 134

def head(*routes, &block)    Nancy.make_camping_route('head', routes, self, &block) end


136
# File 'lib/camping/gear/nancy.rb', line 136

def link(*routes, &block)    Nancy.make_camping_route('link', routes, self, &block) end

#patch(*routes, &block) ⇒ Object



135
# File 'lib/camping/gear/nancy.rb', line 135

def patch(*routes, &block)   Nancy.make_camping_route('patch', routes, self, &block) end

#post(*routes, &block) ⇒ Object



132
# File 'lib/camping/gear/nancy.rb', line 132

def post(*routes, &block)    Nancy.make_camping_route('post', routes, self, &block) end

#put(*routes, &block) ⇒ Object



131
# File 'lib/camping/gear/nancy.rb', line 131

def put(*routes, &block)     Nancy.make_camping_route('put', routes, self, &block) end

#to_procObject

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



164
# File 'lib/camping/gear/nancy.rb', line 164

def to_proc = method(:call).to_proc


137
# File 'lib/camping/gear/nancy.rb', line 137

def unlink(*routes, &block)  Nancy.make_camping_route('unlink', routes, self, &block) end