Class: Kin::Nav::ItemMatcher
- Inherits:
-
Object
- Object
- Kin::Nav::ItemMatcher
- Defined in:
- lib/kin/nav.rb
Overview
Used to match a controller name and action name to an item.
This is used to find out which item should be considered active for the given controller and action.
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the item which this matcher is associated.
Instance Method Summary collapse
-
#action? ⇒ Boolean
Returns if this is matcher has an action specified.
-
#controller? ⇒ Boolean
Returns if this matcher has a controller specified.
-
#initialize(item, controller_name, action_name) ⇒ ItemMatcher
constructor
private
Creates a new ItemMatcher instance.
-
#matches?(controller) ⇒ Boolean
Attempts to match against the given controller.
Constructor Details
#initialize(item, controller_name, action_name) ⇒ ItemMatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new ItemMatcher instance.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/kin/nav.rb', line 299 def initialize(item, controller_name, action_name) # Can't use match an action name with a generic controller. if controller_name == '*' && action_name != '*' # @todo spec raise ArgumentError, "Can't match any controller with a specific " \ "action: #{controller_name}/#{action_name}" end @item = item @controller_name = controller_name if match = action_name.match(/^\{(.*)\}$/) # The action name is a glob containing multiple actions. @action_name = match[1].split(',') else @action_name = [action_name] end end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the item which this matcher is associated.
283 284 285 |
# File 'lib/kin/nav.rb', line 283 def item @item end |
Instance Method Details
#action? ⇒ Boolean
Returns if this is matcher has an action specified.
336 337 338 |
# File 'lib/kin/nav.rb', line 336 def action? @action_name.any? && @action_name.first != '*' end |
#controller? ⇒ Boolean
Returns if this matcher has a controller specified.
325 326 327 |
# File 'lib/kin/nav.rb', line 325 def controller? @controller_name && @controller_name != '*' end |
#matches?(controller) ⇒ Boolean
Attempts to match against the given controller.
350 351 352 353 354 355 356 357 358 359 |
# File 'lib/kin/nav.rb', line 350 def matches?(controller) if not controller? true elsif not action? @controller_name == controller.controller_name else @controller_name == controller.controller_name && @action_name.include?(controller.action_name) end end |