Module: Derailleur::Grease::ClassMethods
- Defined in:
- lib/derailleur/base/grease.rb
Instance Attribute Summary collapse
-
#handler_generator ⇒ Object
The class to use to create handlers that will catch requests.
Instance Method Summary collapse
-
#delete(path, params = nil, &blk) ⇒ Object
Same as get but for DELETE.
-
#get(path, params = nil, &blk) ⇒ Object
Sets a specification to registers a handler at the given path and HTTP request “GET”.
-
#head(path, params = nil, &blk) ⇒ Object
Same as get but for HEAD.
-
#include_and_inherit_HTTP_method(mod) ⇒ Object
Includes a module and then copies its registrations with inherit_HTTP_method.
-
#inherit_HTTP_method(mod) ⇒ Object
Copies the registrations of an object.
-
#post(path, params = nil, &blk) ⇒ Object
Same as get but for POST.
-
#put(path, params = nil, &blk) ⇒ Object
Same as get but for PUT.
-
#registrations ⇒ Object
Returns (and create if needed) the list of registrations.
Instance Attribute Details
#handler_generator ⇒ Object
The class to use to create handlers that will catch requests.
70 71 72 |
# File 'lib/derailleur/base/grease.rb', line 70 def handler_generator @handler_generator ||= Derailleur::HandlerGenerator end |
Instance Method Details
#delete(path, params = nil, &blk) ⇒ Object
Same as get but for DELETE
102 103 104 105 |
# File 'lib/derailleur/base/grease.rb', line 102 def delete(path, params=nil, &blk) registrations << Registration.new(:delete, path, params, handler_generator.for(params, &blk)) end |
#get(path, params = nil, &blk) ⇒ Object
Sets a specification to registers a handler at the given path and HTTP request “GET”. For the default handler_generator (Derailleur::HandlerGenerator), the block blk will be evaluated in a Derailleur::Context .
78 79 80 81 |
# File 'lib/derailleur/base/grease.rb', line 78 def get(path, params=nil, &blk) registrations << Registration.new(:get, path, handler_generator.for(params, &blk)) end |
#head(path, params = nil, &blk) ⇒ Object
Same as get but for HEAD
84 85 86 87 |
# File 'lib/derailleur/base/grease.rb', line 84 def head(path, params=nil, &blk) registrations << Registration.new(:head, path, params, handler_generator.for(params, &blk)) end |
#include_and_inherit_HTTP_method(mod) ⇒ Object
Includes a module and then copies its registrations with inherit_HTTP_method
57 58 59 60 |
# File 'lib/derailleur/base/grease.rb', line 57 def include_and_inherit_HTTP_method(mod) include mod inherit_HTTP_method(mod) end |
#inherit_HTTP_method(mod) ⇒ Object
Copies the registrations of an object. no check is done on duplicate registrations.
49 50 51 52 53 |
# File 'lib/derailleur/base/grease.rb', line 49 def inherit_HTTP_method(mod) mod.registrations.each do |reg| registrations << reg.dup end end |
#post(path, params = nil, &blk) ⇒ Object
Same as get but for POST
90 91 92 93 |
# File 'lib/derailleur/base/grease.rb', line 90 def post(path, params=nil, &blk) registrations << Registration.new(:post, path, params, handler_generator.for(params, &blk)) end |
#put(path, params = nil, &blk) ⇒ Object
Same as get but for PUT
96 97 98 99 |
# File 'lib/derailleur/base/grease.rb', line 96 def put(path, params=nil, &blk) registrations << Registration.new(:put, path, params, handler_generator.for(params, &blk)) end |
#registrations ⇒ Object
Returns (and create if needed) the list of registrations
63 64 65 |
# File 'lib/derailleur/base/grease.rb', line 63 def registrations @registrations ||= [] end |