Class: Shoppe::NavigationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/shoppe/navigation_manager.rb

Defined Under Namespace

Classes: NavigationItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ NavigationManager

Returns a new instance of NavigationManager.


28
29
30
# File 'lib/shoppe/navigation_manager.rb', line 28

def initialize(identifier)
  @identifier = identifier
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier


26
27
28
# File 'lib/shoppe/navigation_manager.rb', line 26

def identifier
  @identifier
end

Class Method Details

.build(identifier, &block) ⇒ Object


12
13
14
15
16
# File 'lib/shoppe/navigation_manager.rb', line 12

def self.build(identifier, &block)
  manager = self.new(identifier.to_s)
  manager.instance_eval(&block) if block_given?
  managers << manager
end

.create(identifier) ⇒ Object


8
9
10
# File 'lib/shoppe/navigation_manager.rb', line 8

def self.create(identifier)
  managers << self.new(identifier.to_s)
end

.find(identifier) ⇒ Object


18
19
20
# File 'lib/shoppe/navigation_manager.rb', line 18

def self.find(identifier)
  managers.select { |m| m.identifier == identifier.to_s }.first
end

.managersObject


4
5
6
# File 'lib/shoppe/navigation_manager.rb', line 4

def self.managers
  @managers ||= []
end

.render(identifier) ⇒ Object


22
23
24
# File 'lib/shoppe/navigation_manager.rb', line 22

def self.render(identifier)
  find(identifier).try(:to_html)
end

Instance Method Details

#add_item(identifier, options = {}, &block) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'lib/shoppe/navigation_manager.rb', line 36

def add_item(identifier, options = {}, &block)
  item                  = NavigationItem.new
  item.manager          = self
  item.identifier       = identifier.to_s
  item.url              = options[:url]             if options[:url]
  item.link_options     = options[:link_options]    if options[:link_options]
  item.active_if        = block                     if block_given?
  items << item
end

#itemsObject


32
33
34
# File 'lib/shoppe/navigation_manager.rb', line 32

def items
  @items ||= []
end

#remove_item(identifier) ⇒ Object


46
47
48
# File 'lib/shoppe/navigation_manager.rb', line 46

def remove_item(identifier)
  items.delete_if { |i| i.identifier.to_s == identifier.to_s }
end