Skip to content

Commit

Permalink
Stop examples/dsl_menus.rb erroring;
Browse files Browse the repository at this point in the history
This example still does not render the menu, but now does not error.

Partially addresses #362.
  • Loading branch information
gavinlaking committed Feb 22, 2016
1 parent 139f46a commit d9dda61
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/vedeu/menus/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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]

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d9dda61

Please sign in to comment.