Class: Babylon::Route
- Inherits:
-
Object
- Object
- Babylon::Route
- Defined in:
- lib/babylon/router.rb
Overview
Route class which associate an XPATH match and a priority to a controller and an action
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#xpath ⇒ Object
Returns the value of attribute xpath.
Instance Method Summary collapse
-
#accepts?(stanza) ⇒ Boolean
Checks that the route matches the stanzas and calls the the action on the controller.
-
#initialize(params) ⇒ Route
constructor
Creates a new route.
Constructor Details
#initialize(params) ⇒ Route
Creates a new route
83 84 85 86 87 88 89 90 91 |
# File 'lib/babylon/router.rb', line 83 def initialize(params) raise("No controller given for route") unless params["controller"] raise("No action given for route") unless params["action"] raise("No xpath given for route") unless params["xpath"] @priority = params["priority"] || 0 @xpath = params["xpath"] @controller = Kernel.const_get("#{params["controller"].capitalize}Controller") @action = params["action"] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
79 80 81 |
# File 'lib/babylon/router.rb', line 79 def action @action end |
#controller ⇒ Object
Returns the value of attribute controller.
79 80 81 |
# File 'lib/babylon/router.rb', line 79 def controller @controller end |
#priority ⇒ Object
Returns the value of attribute priority.
79 80 81 |
# File 'lib/babylon/router.rb', line 79 def priority @priority end |
#xpath ⇒ Object
Returns the value of attribute xpath.
79 80 81 |
# File 'lib/babylon/router.rb', line 79 def xpath @xpath end |
Instance Method Details
#accepts?(stanza) ⇒ Boolean
Checks that the route matches the stanzas and calls the the action on the controller.
95 96 97 |
# File 'lib/babylon/router.rb', line 95 def accepts?(stanza) stanza.xpath(@xpath, XpathHelper.new).empty? ? false : self end |