From d9dda61039199be2cf92240c398fa742598ee28f Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Mon, 22 Feb 2016 21:44:20 +0000 Subject: [PATCH] Stop examples/dsl_menus.rb erroring; This example still does not render the menu, but now does not error. Partially addresses #362. --- lib/vedeu/menus/menu.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/vedeu/menus/menu.rb b/lib/vedeu/menus/menu.rb index 199993f09..bcca96400 100644 --- a/lib/vedeu/menus/menu.rb +++ b/lib/vedeu/menus/menu.rb @@ -11,9 +11,9 @@ class Menu include Vedeu::Repositories::Model - # @!attribute [rw] collection + # @!attribute [w] collection # @return [Array] - attr_accessor :collection + attr_writer :collection # Returns the index of the value in the collection which is # current. @@ -50,12 +50,17 @@ def initialize(attributes = {}) end end + # @return [Array] + def collection + @collection || [] + end + # Returns the item from the collection which shares the same # index as the value of {Vedeu::Menus::Menu#current}. # # @return [void] def current_item - @collection[@current] + collection[@current] end # Returns a DSL instance responsible for defining the DSL @@ -77,7 +82,7 @@ def deputy(client = nil) def selected_item return nil unless @selected - @collection[@selected] + collection[@selected] end # Returns a new collection of items. @@ -94,7 +99,7 @@ def selected_item # @return [Array] def items items = [] - @collection.each_with_index do |item, index| + collection.each_with_index do |item, index| items << if index == @current && index == @selected [true, true, item] @@ -116,7 +121,7 @@ def items # # @return [Array] def view - items[@current, @collection.size] + items[@current, collection.size] end # Sets the value of current to be the first item of the @@ -183,14 +188,14 @@ def deselect_item # # @return [Fixnum] def last - @collection.size - 1 + collection.size - 1 end # Returns the size of the collection. # # @return [Fixnum] def size - @collection.size + collection.size end private