Class: HttpRouter::Node::Root

Inherits:
HttpRouter::Node show all
Defined in:
lib/http_router/node/root.rb

Instance Attribute Summary collapse

Attributes inherited from HttpRouter::Node

#router

Instance Method Summary collapse

Methods inherited from HttpRouter::Node

#add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_host, #add_lookup, #add_match, #add_request_method, #add_scheme, #add_spanning_match, #add_user_agent, #add_variable, #inspect, #inspect_matchers_body, #usable?

Constructor Details

#initialize(router) ⇒ Root

Returns a new instance of Root.



6
7
8
9
# File 'lib/http_router/node/root.rb', line 6

def initialize(router)
  super(router, nil)
  @counter, @methods_module = 0, Module.new
end

Instance Attribute Details

#compiledObject (readonly) Also known as: compiled?

Returns the value of attribute compiled.



4
5
6
# File 'lib/http_router/node/root.rb', line 4

def compiled
  @compiled
end

#methods_moduleObject (readonly)

Returns the value of attribute methods_module.



4
5
6
# File 'lib/http_router/node/root.rb', line 4

def methods_module
  @methods_module
end

Instance Method Details

#compile(routes) ⇒ Object



33
34
35
36
37
38
# File 'lib/http_router/node/root.rb', line 33

def compile(routes)
  routes.each {|route| add_route(route)}
  root.extend(root.methods_module)
  instance_eval "def call(request, &callback)\n#{to_code}\nnil\nend"
  @compiled = true
end

#depthObject



25
26
27
# File 'lib/http_router/node/root.rb', line 25

def depth
  0
end

#inject_root_ivar(obj) ⇒ Object



19
20
21
22
23
# File 'lib/http_router/node/root.rb', line 19

def inject_root_ivar(obj)
  name = :"@ivar_#{@counter += 1}"
  root.instance_variable_set(name, obj)
  name
end

#inspect_labelObject



29
30
31
# File 'lib/http_router/node/root.rb', line 29

def inspect_label
  "Root (#{@matchers.size} matchers)"
end

#next_counterObject



15
16
17
# File 'lib/http_router/node/root.rb', line 15

def next_counter
  @counter += 1
end

#uncompileObject



11
12
13
# File 'lib/http_router/node/root.rb', line 11

def uncompile
  instance_eval "undef :call; def call(req); raise 'uncompiled root'; end", __FILE__, __LINE__ if compiled?
end