Class Babylon::Router::DSL
In: lib/babylon/router/dsl.rb
Parent: Object

Creates a simple DSL for stanza routing.

Methods

disco_for   disco_info   disco_items   new   priority   set   to   xpath  

Attributes

routes  [R] 

Public Class methods

[Source]

    # File lib/babylon/router/dsl.rb, line 8
 8:       def initialize
 9:         @routes = []
10:       end

Public Instance methods

Match a disco_info query.

[Source]

    # File lib/babylon/router/dsl.rb, line 25
25:       def disco_info(node = nil)
26:         disco_for(:info, node)
27:       end

Match a disco_items query.

[Source]

    # File lib/babylon/router/dsl.rb, line 30
30:       def disco_items(node = nil)
31:         disco_for(:items, node)
32:       end

Set the priority of the last created route.

[Source]

    # File lib/babylon/router/dsl.rb, line 19
19:       def priority(n)
20:         set(:priority, n)
21:         self
22:       end

Map a route to a specific controller and action.

[Source]

    # File lib/babylon/router/dsl.rb, line 35
35:       def to(params)
36:         set(:controller, params[:controller])
37:         set(:action, params[:action])
38:         # We now have all the properties we really need to create a route.
39:         route = Route.new(@routes.pop)
40:         @routes << route
41:         self
42:       end

Match an xpath.

[Source]

    # File lib/babylon/router/dsl.rb, line 13
13:       def xpath(path)
14:         @routes << {"xpath" => path}
15:         self
16:       end

Protected Instance methods

[Source]

    # File lib/babylon/router/dsl.rb, line 53
53:       def disco_for(type, node = nil)
54:         str = "//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco##{type.to_s}')"
55:         str += " and @node = '#{node}'" if node
56:         str += "]"
57:         xpath(str)
58:       end

We do this magic, or crap depending on your perspective, because we don‘t know whether we‘re setting values on a Hash or a Route. We can‘t create the Route until we have a controller and action.

[Source]

    # File lib/babylon/router/dsl.rb, line 47
47:       def set(property, value)
48:         last = @routes.last
49:         last[property.to_s] = value if last.is_a?(Hash)
50:         last.send("#{property.to_s}=", value) if last.is_a?(Route)
51:       end

[Validate]