Class: Kitestrings::Menu::ItemCollection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Kitestrings::Menu::ItemCollection
- Defined in:
- lib/kitestrings/menu/item_collection.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(loaded_resources) ⇒ ItemCollection
constructor
A new instance of ItemCollection.
Constructor Details
#initialize(loaded_resources) ⇒ ItemCollection
Returns a new instance of ItemCollection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kitestrings/menu/item_collection.rb', line 7 def initialize(loaded_resources) length = loaded_resources.length @items = (0...length).map do |count| Menu::Item.new loaded_resources[0..count] end # if the last item in the resources is a new_record? object, then substitute it for the class. This will # cause polymorphic path to show the #index action in the breadcrumb instead of the new action, or a route # error looking for an object that has no id. last = @items.last if last && last.object.respond_to?(:new_record?) && last.object.new_record? @items.pop @items << Menu::Item.new(last.resources[0..-2] + [last.object.class]) end # the last item in the array is assumed to be active. @items.last.active = true unless items.empty? # delegate all methods to this array object super(@items) end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/kitestrings/menu/item_collection.rb', line 5 def items @items end |