Class: Babylon::Route

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#actionObject

Returns the value of attribute action.



79
80
81
# File 'lib/babylon/router.rb', line 79

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



79
80
81
# File 'lib/babylon/router.rb', line 79

def controller
  @controller
end

#priorityObject

Returns the value of attribute priority.



79
80
81
# File 'lib/babylon/router.rb', line 79

def priority
  @priority
end

#xpathObject

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.

Returns:

  • (Boolean)


95
96
97
# File 'lib/babylon/router.rb', line 95

def accepts?(stanza)
  stanza.xpath(@xpath, XpathHelper.new).empty? ? false : self
end