Class: DripDrop::Node::Nodelet

Inherits:
Object
  • Object
show all
Defined in:
lib/dripdrop/node/nodelet.rb

Overview

See the documentation for nodelet in DripDrop::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, name, *configure_args) ⇒ Nodelet

Returns a new instance of Nodelet.



6
7
8
9
10
11
# File 'lib/dripdrop/node/nodelet.rb', line 6

def initialize(ctx, name, *configure_args) 
  @ctx              = ctx
  @name             = name
  @internal_routing = {}
  configure(*configure_args)
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



28
29
30
31
32
33
# File 'lib/dripdrop/node/nodelet.rb', line 28

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

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/dripdrop/node/nodelet.rb', line 4

def name
  @name
end

#routingObject

Returns the value of attribute routing.



4
5
6
# File 'lib/dripdrop/node/nodelet.rb', line 4

def routing
  @routing
end

Instance Method Details

#configure(*args) ⇒ Object



13
14
15
# File 'lib/dripdrop/node/nodelet.rb', line 13

def configure(*args)
  # Do nothing!
end

#route(name, handler_type, *handler_args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/dripdrop/node/nodelet.rb', line 17

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