Class: Coroutine::TinyNavigation::Data::Navigation

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_navigation/data/navigation.rb

Overview

This class represents a navigation tree. It holds all the data for tree and provides a number of convenience methods related to that tree.

Direct Known Subclasses

Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, current_controller, &block) ⇒ Navigation

This method creates a new navigation data object.

name is the unique identifer of the navigation.

current_controller the currently loaded controller

The block given to the navigation item is used to define navigation items of this navigation object.



21
22
23
24
25
26
27
# File 'lib/tiny_navigation/data/navigation.rb', line 21

def initialize(name, current_controller, &block)
  @items                  = []
  @name                   = name
  @current_controller     = current_controller

  self.instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

This method delegates method missing calls to the controller, in case the navigation item has user-defined properties.



47
48
49
# File 'lib/tiny_navigation/data/navigation.rb', line 47

def method_missing(method_name, *args) #:nodoc:
  @current_controller.send method_name, *args
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



10
11
12
# File 'lib/tiny_navigation/data/navigation.rb', line 10

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/tiny_navigation/data/navigation.rb', line 10

def name
  @name
end

Instance Method Details

#selected(item = self) ⇒ Object

This method returns an array of selected navigation items. The array represents a bread-crumb list in that the head of the list represents a top-level navigation item, and the tail of the list represents selected sub-navigation items.

item is the reference point for the calculation.



36
37
38
39
40
41
42
# File 'lib/tiny_navigation/data/navigation.rb', line 36

def selected(item=self)
  items = []
  item.items.each do |item|
    items << item << selected(item) if item.selected?
  end
  items.flatten
end