Class: DripDrop::Node::Nodelet
- Inherits:
-
Object
- Object
- DripDrop::Node::Nodelet
- Defined in:
- lib/dripdrop/node/nodelet.rb
Overview
See the documentation for nodelet
in DripDrop::Node
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#routing ⇒ Object
Returns the value of attribute routing.
Instance Method Summary collapse
-
#initialize(ctx, name, routes) ⇒ Nodelet
constructor
A new instance of Nodelet.
-
#method_missing(meth, *args) ⇒ Object
Check for the method as a route in @ctx, if found memoize it by defining it as a singleton.
- #route(name, handler_type, *handler_args) ⇒ Object
Constructor Details
#initialize(ctx, name, routes) ⇒ Nodelet
Returns a new instance of Nodelet.
6 7 8 9 10 |
# File 'lib/dripdrop/node/nodelet.rb', line 6 def initialize(ctx, name, routes) @ctx = ctx @name = name @internal_routing = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Check for the method as a route in @ctx, if found memoize it by defining it as a singleton
23 24 25 26 27 28 |
# File 'lib/dripdrop/node/nodelet.rb', line 23 def method_missing(meth,*args) (class << self; self; end).class_eval do define_method(meth) { @ctx.send(meth,*args) } end self.send(meth,*args) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/dripdrop/node/nodelet.rb', line 4 def name @name end |
#routing ⇒ Object
Returns the value of attribute routing.
4 5 6 |
# File 'lib/dripdrop/node/nodelet.rb', line 4 def routing @routing end |
Instance Method Details
#route(name, handler_type, *handler_args) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/dripdrop/node/nodelet.rb', line 12 def route(name,handler_type,*handler_args) handler = @ctx.route_full(self, name, handler_type, *handler_args) @internal_routing[name] = handler (class << self; self; end).class_eval do define_method(name) { handler } end end |