Class: SimpleNavigation::ItemsProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_navigation/items_provider.rb

Overview

Acts as a proxy to navigation items that are passed into the SimpleNavigation::Configuration#items method. It hides the logic for finding items from the Configuration object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ ItemsProvider

It accepts the following types of provider:

  • methodname as symbol - the specified method should return the relevant items and has to be available in the view (a helper method)

  • object that responds to :items

  • enumerable object that represents the items

See SimpleNavigation::ItemAdapter for the requirements that need to be fulfilled by the provided items.



18
19
20
# File 'lib/simple_navigation/items_provider.rb', line 18

def initialize(provider)
  @provider = provider
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



7
8
9
# File 'lib/simple_navigation/items_provider.rb', line 7

def provider
  @provider
end

Instance Method Details

#itemsObject

Returns the navigation items



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/simple_navigation/items_provider.rb', line 23

def items
  if provider.is_a?(Symbol)
    SimpleNavigation.context_for_eval.send(provider)
  elsif provider.respond_to?(:items)
    provider.items
  elsif provider.respond_to?(:each)
    provider
  else
    fail('items_provider either must be a symbol specifying the '         \
         'helper-method to call, an object with an items-method defined ' \
         'or an enumerable representing the items')
  end
end