Class: Babylon::Router::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/babylon/router/dsl.rb

Overview

Creates a simple DSL for stanza routing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



8
9
10
# File 'lib/babylon/router/dsl.rb', line 8

def initialize
  @routes = []
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



6
7
8
# File 'lib/babylon/router/dsl.rb', line 6

def routes
  @routes
end

Instance Method Details

#disco_info(node = nil) ⇒ Object

Match a disco_info query.



25
26
27
# File 'lib/babylon/router/dsl.rb', line 25

def disco_info(node = nil)
  disco_for(:info, node)
end

#disco_items(node = nil) ⇒ Object

Match a disco_items query.



30
31
32
# File 'lib/babylon/router/dsl.rb', line 30

def disco_items(node = nil)
  disco_for(:items, node)
end

#priority(n) ⇒ Object

Set the priority of the last created route.



19
20
21
22
# File 'lib/babylon/router/dsl.rb', line 19

def priority(n)
  set(:priority, n)
  self
end

#to(params) ⇒ Object

Map a route to a specific controller and action.



35
36
37
38
39
40
41
42
# File 'lib/babylon/router/dsl.rb', line 35

def to(params)
  set(:controller, params[:controller])
  set(:action, params[:action])
  # We now have all the properties we really need to create a route.
  route = Route.new(@routes.pop)
  @routes << route
  self
end

#xpath(path) ⇒ Object

Match an xpath.



13
14
15
16
# File 'lib/babylon/router/dsl.rb', line 13

def xpath(path)
  @routes << {"xpath" => path}
  self
end