Module: Derailleur::Grease
- Includes:
- Application
- Defined in:
- lib/derailleur/base/grease.rb
Overview
The Grease is the module that helps you code at a high level, with blocks. Basically, including this method in a class makes the HTTP methods definition available as registrations. Then, instanciating the class, it will actually register the routes in the objects. Including Grease will redefine the “initialize method”, do do not include Grease after defining it. Do the opposite. See also Grease#initialize_HTTP (you should call it if you don’t use Grease’s initialize method.
Defined Under Namespace
Modules: ClassMethods Classes: Registration
Instance Attribute Summary
Attributes included from Application
#default_dispatcher, #default_handler, #default_internal_error_handler, #default_root_node_type
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args, &blk) ⇒ Object
If there is no initializer, will create one.
-
#initialize_HTTP ⇒ Object
Initialiazes HTTP routes by transforming all the registration definitions in the class of the object into itself.
-
#register_registrations_of(obj) ⇒ Object
Transform registration definitions into actual registrations.
Methods included from Application
#build_route, #call, #chunk_path, #default_node_type, #delete, #get, #get_route, #get_route_silent, #get_route_with_params, #head, #normalize, #post, #put, #register_route, #routes, #split_to!, #undelete, #unget, #unhead, #unpost, #unput, #unregister_route
Class Method Details
.included(klass) ⇒ Object
20 21 22 |
# File 'lib/derailleur/base/grease.rb', line 20 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#initialize(*args, &blk) ⇒ Object
If there is no initializer, will create one. If there is one, then it will try to call super. As a result include this module into classes before defining initialize, or in classes in which you don’t care about initialize.
41 42 43 44 |
# File 'lib/derailleur/base/grease.rb', line 41 def initialize(*args, &blk) super initialize_HTTP end |
#initialize_HTTP ⇒ Object
Initialiazes HTTP routes by transforming all the registration definitions in the class of the object into itself.
33 34 35 |
# File 'lib/derailleur/base/grease.rb', line 33 def initialize_HTTP register_registrations_of(self.class) end |
#register_registrations_of(obj) ⇒ Object
Transform registration definitions into actual registrations.
25 26 27 28 29 |
# File 'lib/derailleur/base/grease.rb', line 25 def register_registrations_of(obj) obj.registrations.each do |reg| send(reg.sym, reg.path, reg.handler) end end |